Skip to content

Instantly share code, notes, and snippets.

@toddlahman
Created February 13, 2014 12:51
Show Gist options
  • Save toddlahman/8974532 to your computer and use it in GitHub Desktop.
Save toddlahman/8974532 to your computer and use it in GitHub Desktop.
API Manager api_manager_extra_software_status_data filter hook function usage example
<?php
function api_manager_example_get_activation_info( $activation_info ) {
return $activation_info;
}
add_filter( 'api_manager_extra_software_status_data', 'api_manager_example_get_activation_info' );
@trueqap
Copy link

trueqap commented Apr 4, 2023

It's really hard to reach you, Todd! I found some security issues in the API plugin. Where can I send them that isn't woo support? You're my role model, seriously. It even costs money if someone wants to write to you :D I love it...

Other bugs:

Fatal error: Uncaught Exception: DateTime::__construct(): Failed to parse time string (2023.03.31. 11:50) at position 5 (0): Double time specification in plugins/woocommerce-api-manager/includes/wc-am-format.php on line 168
public function date_to_time( $date, $offset = true ) {
		if ( $date == 0 ) {
			return 0;
		}

		$date_time = new WC_DateTime( $date, new DateTimeZone( 'UTC' ) );

		return ( $offset ) ? intval( $date_time->getOffsetTimestamp() ) : intval( $date_time->getTimestamp() );
	}

My fix:

public function date_to_time($date, $offset = true)
    {
        if ($date == 0) {
            return 0;
        }

	   $date = str_replace(".", "-", substr($date, 0, 10)) . " " . substr($date, 11);

        $date_time = new WC_DateTime($date, new DateTimeZone('UTC'));

        return ($offset) ? intval($date_time->getOffsetTimestamp()) : intval($date_time->getTimestamp());
    }

@toddlahman
Copy link
Author

@trueqap No changes are required for the date_to_time().

The error indicates the date string passed to date_to_time() was not properly formatted for the DateTime class.

https://www.php.net/manual/en/datetime.construct.php
https://www.php.net/manual/en/datetime.formats.php

There are methods that use date_to_time() in the API Manager that can serve as an example.

If you'd like to list the security issues here I'd be happy to look at them.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment