This email is sent from your MainWP Dashboard.
If you do not wish to receive these notices please re-check your preferences in the MainWP Settings page.
';
}
static function update_option( $option_name, $option_value, $autoload = 'no' ) {
$success = add_option( $option_name, $option_value, '', $autoload );
if ( ! $success ) {
$success = update_option( $option_name, $option_value );
}
return $success;
}
static function fix_option( $option_name, $autoload = 'no' ) {
global $wpdb;
if ( $autoload != $wpdb->get_var( $wpdb->prepare( "SELECT autoload FROM $wpdb->options WHERE option_name = %s", $option_name ) ) ) {
$option_value = get_option( $option_name );
delete_option( $option_name );
add_option( $option_name, $option_value, null, $autoload );
}
}
static function containsAll( $haystack, $needle ) {
if ( ! is_array( $haystack ) || ! is_array( $needle ) ) {
return false;
}
foreach ( $needle as $item ) {
if ( ! in_array( $item, $haystack ) ) {
return false;
}
}
return true;
}
public static function getRevisions( $max_revisions ) {
global $wpdb;
$sql = " SELECT `post_parent`, COUNT(*) cnt
FROM $wpdb->posts
WHERE `post_type` = 'revision'
GROUP BY `post_parent`
HAVING COUNT(*) > " . $max_revisions;
return $wpdb->get_results( $sql );
}
public static function deleteRevisions( $results, $max_revisions ) {
global $wpdb;
if ( ! is_array( $results ) || 0 === count( $results ) ) {
return;
}
$count_deleted = 0;
$results_length = count( $results );
for ( $i = 0; $i < $results_length; $i ++ ) {
$number_to_delete = $results[ $i ]->cnt - $max_revisions;
$count_deleted += $number_to_delete;
$sql_get = "
SELECT `ID`, `post_modified`
FROM $wpdb->posts
WHERE `post_parent`=" . $results[ $i ]->post_parent . "
AND `post_type`='revision'
ORDER BY `post_modified` ASC
";
$results_posts = $wpdb->get_results( $sql_get );
$delete_ids = array();
if ( is_array( $results_posts ) && count( $results_posts ) > 0 ) {
for ( $j = 0; $j < $number_to_delete; $j ++ ) {
$delete_ids[] = $results_posts[ $j ]->ID;
}
}
if ( count( $delete_ids ) > 0 ) {
$sql_delete = " DELETE FROM $wpdb->posts
WHERE `ID` IN (" . implode( ',', $delete_ids ) . ')
';
$wpdb->get_results( $sql_delete );
}
}
return $count_deleted;
}
public static function inExcludes( $excludes, $value ) {
if ( empty( $value ) ) {
return false;
}
if ( null != $excludes ) {
foreach ( $excludes as $exclude ) {
if ( MainWP_Helper::endsWith( $exclude, '*' ) ) {
if ( MainWP_Helper::startsWith( $value, substr( $exclude, 0, strlen( $exclude ) - 1 ) ) ) {
return true;
}
} else if ( $value == $exclude ) {
return true;
} else if ( MainWP_Helper::startsWith( $value, $exclude . '/' ) ) {
return true;
}
}
}
return false;
}
public static function isArchive( $pFileName, $pPrefix = '', $pSuffix = '' ) {
return preg_match( '/' . $pPrefix . '(.*).(zip|tar|tar.gz|tar.bz2)' . $pSuffix . '$/', $pFileName );
}
public static function parse_query( $var ) {
$var = parse_url( $var, PHP_URL_QUERY );
$var = html_entity_decode( $var );
$var = explode( '&', $var );
$arr = array();
foreach ( $var as $val ) {
$x = explode( '=', $val );
$arr[ $x[0] ] = $x[1];
}
unset( $val, $x, $var );
return $arr;
}
/**
* Allow to remove method for an hook when, it's a class method used and class don't have variable, but you know the class name :)
* Credit to the : wp-filters-extras
*/
public static function remove_filters_for_anonymous_class( $hook_name = '', $class_name = '', $method_name = '', $priority = 0 ) {
global $wp_filter;
// Take only filters on right hook name and priority
if ( ! isset( $wp_filter[ $hook_name ] ) || ! isset( $wp_filter[ $hook_name ][ $priority ] ) || ! is_array( $wp_filter[ $hook_name ][ $priority ] ) ) {
return false;
}
// Loop on filters registered
foreach ( (array) $wp_filter[ $hook_name ][ $priority ] as $unique_id => $filter_array ) {
// Test if filter is an array ! (always for class/method)
if ( isset( $filter_array['function'] ) && is_array( $filter_array['function'] ) ) {
// Test if object is a class, class and method is equal to param !
if ( is_object( $filter_array['function'][0] ) && get_class( $filter_array['function'][0] ) && get_class( $filter_array['function'][0] ) === $class_name && $filter_array['function'][1] === $method_name ) {
unset( $wp_filter[ $hook_name ][ $priority ][ $unique_id ] );
}
}
}
return false;
}
/**
* Credit to the : wp-filters-extras
*/
public static function remove_filters_with_method_name( $hook_name = '', $method_name = '', $priority = 0 ) {
global $wp_filter;
// Take only filters on right hook name and priority
if ( ! isset( $wp_filter[ $hook_name ] ) || ! isset( $wp_filter[ $hook_name ][ $priority ] ) || ! is_array( $wp_filter[ $hook_name ][ $priority ] ) ) {
return false;
}
// Loop on filters registered
foreach ( (array) $wp_filter[ $hook_name ][ $priority ] as $unique_id => $filter_array ) {
// Test if filter is an array ! (always for class/method)
if ( isset( $filter_array['function'] ) && $filter_array['function'] === $method_name ) {
unset( $wp_filter[ $hook_name ][ $priority ][ $unique_id ] );
}
}
return false;
}
public static function sanitize_filename( $filename ) {
// Remove anything which isn't a word, whitespace, number
// or any of the following caracters -_~,;:[]().
// If you don't need to handle multi-byte characters
// you can use preg_replace rather than mb_ereg_replace
// Thanks @Łukasz Rysiak!
$filename = mb_ereg_replace( "([^\w\s\d\-_~,;:\[\]\(\).])", '', $filename );
// Remove any runs of periods (thanks falstro!)
$filename = mb_ereg_replace( "([\.]{2,})", '', $filename );
return $filename;
}
}