Automattic\WooCommerce\Internal\Admin\RemoteFreeExtensions

Init{}WC 1.0└─ RemoteSpecsEngine

Remote Payment Methods engine. This goes through the specs and gets eligible payment methods.

Хуков нет.

Использование

$Init = new Init();
// use class methods

Методы

  1. public __construct()
  2. public evaluate_bundles( $specs, $allowed_bundles )
  3. public add_action( 'woocommerce_updated', array( __CLASS__, 'delete_specs_transient' ) )
  4. public function( $bundle )
  5. public static delete_specs_transient()
  6. public log_errors( $results['errors'] )
  7. public if ( $specs_to_save )
  8. public static get_extensions( $allowed_bundles = array() )
  9. public static get_specs()
  10. public elseif ( count( $results['errors'] ) > 0 )
  11. ERROR: no method name found on line `}`
  12. ERROR: no method name found on line ``
  13. ERROR: no method name found on line `*/`
  14. ERROR: no method name found on line `*/`
  15. ERROR: no method name found on line `}`
  16. ERROR: no method name found on line ``
  17. ERROR: no method name found on line ``
  18. ERROR: no method name found on line ``
  19. ERROR: no method name found on line ``
  20. ERROR: no method name found on line ``
  21. ERROR: no method name found on line `$specs_to_return = $results['bundles'];`
  22. ERROR: no method name found on line ``
  23. ERROR: no method name found on line ``
  24. ERROR: no method name found on line `$results['bundles'],`
  25. ERROR: no method name found on line ``
  26. ERROR: no method name found on line ``
  27. ERROR: no method name found on line ``
  28. ERROR: no method name found on line ``
  29. ERROR: no method name found on line `$specs_to_save = null;`
  30. ERROR: no method name found on line ``
  31. ERROR: no method name found on line ``
  32. ERROR: no method name found on line ``
  33. ERROR: no method name found on line ``
  34. ERROR: no method name found on line `// When no plugins are visible, replace it with defaults and save for 3 hours.`
  35. ERROR: no method name found on line ``
  36. ERROR: no method name found on line `}`
  37. ERROR: no method name found on line `}`
  38. ERROR: no method name found on line `// When no plugins are visible, replace it with defaults and save for 3 hours.`
  39. ERROR: no method name found on line `* Delete the specs transient.`
  40. ERROR: no method name found on line ``
  41. ERROR: no method name found on line ``
  42. ERROR: no method name found on line ``
  43. ERROR: no method name found on line `* Delete the specs transient.`
  44. ERROR: no method name found on line ``
  45. ERROR: no method name found on line ``
  46. ERROR: no method name found on line ``
  47. ERROR: no method name found on line `}`
  48. ERROR: no method name found on line `/**`
  49. ERROR: no method name found on line ``
  50. ERROR: no method name found on line `return $specs_to_return;`
  51. ERROR: no method name found on line ``
  52. ERROR: no method name found on line ``
  53. ERROR: no method name found on line ``
  54. ERROR: no method name found on line ``
  55. ERROR: no method name found on line ``
  56. ERROR: no method name found on line ``
  57. ERROR: no method name found on line ``
  58. ERROR: no method name found on line ``
  59. ERROR: no method name found on line `}`
  60. ERROR: no method name found on line ``
  61. ERROR: no method name found on line ``
  62. ERROR: no method name found on line ``
  63. ERROR: no method name found on line ``
  64. ERROR: no method name found on line ``
  65. ERROR: no method name found on line ``
  66. ERROR: no method name found on line `*/`
  67. ERROR: no method name found on line `/**`
  68. ERROR: no method name found on line ``
  69. ERROR: no method name found on line ``
  70. ERROR: no method name found on line ``
  71. ERROR: no method name found on line ``
  72. ERROR: no method name found on line ``
  73. ERROR: no method name found on line ``
  74. ERROR: no method name found on line ``
  75. ERROR: no method name found on line ``
  76. ERROR: no method name found on line `* @param array $allowed_bundles Optional array of allowed bundles to be returned.`
  77. ERROR: no method name found on line ``
  78. ERROR: no method name found on line ``
  79. ERROR: no method name found on line ``
  80. ERROR: no method name found on line ``
  81. ERROR: no method name found on line `}`
  82. ERROR: no method name found on line ``
  83. ERROR: no method name found on line ``
  84. ERROR: no method name found on line ``
  85. ERROR: no method name found on line ``
  86. ERROR: no method name found on line ``
  87. ERROR: no method name found on line `/**`
  88. ERROR: no method name found on line ``

Код Init{} WC 10.4.3

class Init extends RemoteSpecsEngine {

	/**
	 * Constructor.
	 */
	public function __construct() {
		add_action( 'woocommerce_updated', array( __CLASS__, 'delete_specs_transient' ) );
	}

	/**
	 * Go through the specs and run them.
	 *
	 * @param array $allowed_bundles Optional array of allowed bundles to be returned.
	 * @return array
	 */
	public static function get_extensions( $allowed_bundles = array() ) {
		$locale = get_user_locale();

		$specs           = self::get_specs();
		$results         = EvaluateExtension::evaluate_bundles( $specs, $allowed_bundles );
		$specs_to_return = $results['bundles'];
		$specs_to_save   = null;

		$plugins = array_filter(
			$results['bundles'],
			function( $bundle ) {
				return count( $bundle['plugins'] ) > 0;
			}
		);

		if ( empty( $plugins ) ) {
			// When no plugins are visible, replace it with defaults and save for 3 hours.
			$specs_to_save   = DefaultFreeExtensions::get_all();
			$specs_to_return = EvaluateExtension::evaluate_bundles( $specs_to_save, $allowed_bundles )['bundles'];
		} elseif ( count( $results['errors'] ) > 0 ) {
			// When suggestions is not empty but has errors, save it for 3 hours.
			$specs_to_save = $specs;
		}

		// When plugins is not empty but has errors, save it for 3 hours.
		if ( count( $results['errors'] ) > 0 ) {
			self::log_errors( $results['errors'] );
		}

		if ( $specs_to_save ) {
			RemoteFreeExtensionsDataSourcePoller::get_instance()->set_specs_transient( array( $locale => $specs_to_save ), 3 * HOUR_IN_SECONDS );
		}

		return $specs_to_return;
	}

	/**
	 * Delete the specs transient.
	 */
	public static function delete_specs_transient() {
		RemoteFreeExtensionsDataSourcePoller::get_instance()->delete_specs_transient();
	}

	/**
	 * Get specs or fetch remotely if they don't exist.
	 */
	public static function get_specs() {
		if ( 'no' === get_option( 'woocommerce_show_marketplace_suggestions', 'yes' ) ) {
			return DefaultFreeExtensions::get_all();
		}
		$specs = RemoteFreeExtensionsDataSourcePoller::get_instance()->get_specs_from_data_sources();

		// Fetch specs if they don't yet exist.
		if ( false === $specs || ! is_array( $specs ) || 0 === count( $specs ) ) {
			return DefaultFreeExtensions::get_all();
		}

		return $specs;
	}
}