first commit
This commit is contained in:
@@ -0,0 +1,15 @@
|
||||
<?php
|
||||
|
||||
namespace WPML\TM\WP\App;
|
||||
|
||||
use function WPML\FP\partial;
|
||||
|
||||
class Resources {
|
||||
// enqueueApp :: string $app -> ( string $localizeData )
|
||||
public static function enqueueApp( $app ) {
|
||||
return partial( [ '\WPML\LIB\WP\App\Resources', 'enqueue' ],
|
||||
$app, WPML_TM_URL, WPML_TM_PATH, WPML_TM_VERSION, 'wpml-translation-management'
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,76 @@
|
||||
<?php
|
||||
|
||||
class WPML_TM_Array_Search {
|
||||
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
private $where;
|
||||
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
private $data;
|
||||
|
||||
/**
|
||||
* @param array $data
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function set_data( $data ) {
|
||||
$this->data = $data;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $args
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function set_where( $args ) {
|
||||
$this->where = $args;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function get_results() {
|
||||
$results = array();
|
||||
|
||||
foreach ( $this->where as $key => $clause ) {
|
||||
$operator = isset( $clause['operator'] ) ? strtoupper( $clause['operator'] ) : 'LIKE';
|
||||
|
||||
foreach ( $this->data as $data ) {
|
||||
|
||||
if ( in_array( $data, $results, true ) ) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$field_value = '';
|
||||
|
||||
if ( is_object( $data ) ) {
|
||||
$field_value = $data->{$clause['field']};
|
||||
} elseif ( is_array( $data ) ) {
|
||||
$field_value = $data[ $clause['field'] ];
|
||||
}
|
||||
|
||||
switch ( $operator ) {
|
||||
default:
|
||||
case 'LIKE':
|
||||
if ( false !== strpos( strtolower( $field_value ), strtolower( $clause['value'] ) ) ) {
|
||||
$results[] = $data;
|
||||
}
|
||||
break;
|
||||
case '=':
|
||||
if ( strlen( $field_value ) === strlen( $clause['value'] ) &&
|
||||
0 === strpos( strtolower( $field_value ), strtolower( $clause['value'] ) ) ) {
|
||||
$results[] = $data;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return array_values( $results );
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,47 @@
|
||||
<?php
|
||||
|
||||
class WPML_WP_Cron_Check {
|
||||
|
||||
const TRANSIENT_NAME = 'wpml_cron_check';
|
||||
|
||||
/** @var WPML_PHP_Functions $php_functions */
|
||||
private $php_functions;
|
||||
|
||||
public function __construct( WPML_PHP_Functions $php_functions ) {
|
||||
$this->php_functions = $php_functions;
|
||||
}
|
||||
|
||||
/** @return bool */
|
||||
public function verify() {
|
||||
if ( $this->is_doing_cron() ) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if ( $this->php_functions->constant( 'DISABLE_WP_CRON' ) ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$is_on_from_transient = get_transient( self::TRANSIENT_NAME );
|
||||
|
||||
if ( false !== $is_on_from_transient ) {
|
||||
return (bool) $is_on_from_transient;
|
||||
}
|
||||
|
||||
$is_on = 1;
|
||||
$request = wp_remote_get( site_url( 'wp-cron.php' ) );
|
||||
|
||||
if ( is_wp_error( $request ) ) {
|
||||
$is_on = 0;
|
||||
} elseif ( $request['response']['code'] !== 200 ) {
|
||||
$is_on = 0;
|
||||
}
|
||||
|
||||
set_transient( self::TRANSIENT_NAME, $is_on, 12 * HOUR_IN_SECONDS );
|
||||
return (bool) $is_on;
|
||||
}
|
||||
|
||||
/** @return bool */
|
||||
public function is_doing_cron() {
|
||||
return (bool) $this->php_functions->constant( 'DOING_CRON' );
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user