'; var_dump($var); echo ''; } } if ( ! function_exists('resolve_ip')) { /** * @deprecated 2.0 Use wmvc_resolve_ip() * @see wmvc_resolve_ip() */ function resolve_ip($ip) { if($ip == 'DISABLED') return $ip; if (filter_var($ip, FILTER_VALIDATE_IP)) { // $ip is a valid IP address" } else { return ''; } if($ip == '::1') { return $ip.', local'; } $str = ''.$ip.''; return $str; } } if ( ! function_exists('stringify_attributes')) { /** * Stringify attributes for use in html tags. * * @since 1.0 * @deprecated 2.0 Use wmvc_stringify_attributes() * @see wmvc_stringify_attributes() * * Helper function used to convert an array or object of * attributes to a string * * @param mixed * @return string */ function stringify_attributes($attributes, $js = FALSE) { if (is_object($attributes) && count($attributes) > 0) { $attributes = (array) $attributes; } if (is_array($attributes)) { $atts = ''; if (count($attributes) === 0) { return $atts; } foreach ($attributes as $key => $val) { if ($js) { $atts .= $key.'='.$val.','; } else { $atts .= ' '.$key.'="'.$val.'"'; } } return rtrim($atts, ','); } elseif (is_string($attributes) && strlen($attributes) > 0) { return ' '.$attributes; } return $attributes; } } if ( ! function_exists('anchor')) { /** * Anchor Link * * Creates an anchor based on the local URL. * * @deprecated 2.0 Use wmvc_anchor() * @see wmvc_anchor() * * @param string the URL * @param string the link title * @param mixed any attributes * @return string */ function anchor($uri = '', $title = '', $attributes = '') { $title = (string) $title; $site_url = is_array($uri) ? site_url($uri) : (preg_match('#^(\w+:)?//#i', $uri) ? $uri : site_url($uri)); if ($title === '') { $title = $site_url; } if ($attributes !== '') { $attributes = stringify_attributes($attributes); } return ''.$title.''; } } if ( ! function_exists('btn_edit')) { /** * @deprecated 2.0 Use wmvc_btn_edit() * @see wmvc_btn_edit() */ function btn_edit($uri) { return anchor($uri, '', array('class'=>'btn btn-success btn-xs')); } } if ( ! function_exists('btn_read')) { /** * @deprecated 2.0 Use wmvc_btn_read() * @see wmvc_btn_read() */ function btn_read($uri, $title=NULL) { if(empty($title))$title=__('Read', 'wmvc_win'); return anchor($uri, ' '.$title, array('class'=>'btn btn-primary btn-xs')); } } if ( ! function_exists('btn_open')) { /** * @deprecated 2.0 Use wmvc_btn_open() * @see wmvc_btn_open() */ function btn_open($uri, $target=NULL) { if($target === NULL) $target = '_blank'; return anchor($uri, '', array('class'=>'btn btn-primary btn-xs', 'target'=>$target, 'title'=>__('Open details', 'wmvc_win'))); } } if ( ! function_exists('btn_open_ajax')) { /** * @deprecated 2.0 Use wmvc_btn_open_ajax() * @see wmvc_btn_open_ajax() */ function btn_open_ajax($uri, $target=NULL) { if($target === NULL) $target = '_blank'; return anchor($uri, '', array('class'=>'btn btn-primary btn-xs popup-with-form-ajax', 'target'=>$target, 'title'=>__('Open details', 'wmvc_win'))); } } if ( ! function_exists('btn_delete_noconfirm')) { /** * @deprecated 2.0 Use wmvc_btn_delete_noconfirm() * @see wmvc_btn_delete_noconfirm() */ function btn_delete_noconfirm($uri) { return anchor($uri, ' ', array('class'=>'btn btn-danger btn-xs delete_button')); } } if ( ! function_exists('btn_delete')) { /** * @deprecated 2.0 Use wmvc_btn_delete() * @see wmvc_btn_delete() */ function btn_delete($uri, $confirm_question = TRUE, $title='') { $target = ''; if(isset($_GET['popup'])) { $target = ''; } if($confirm_question) { return anchor($uri, ' ', array( 'target' => $target, 'title' => $title, 'onclick' => 'return confirm(\''.__('Are you sure?', 'wmvc_win').'\')', 'class'=>'btn btn-danger btn-xs delete_button')); } else { return anchor($uri, ' ', array( 'target' => $target, 'title' => $title, 'class'=>'btn btn-danger btn-xs delete_button')); } } } if ( ! function_exists('btn_save')) { /** * @deprecated 2.0 Use wmvc_btn_save() * @see wmvc_btn_save() */ function btn_save($uri, $empty = '-empty') { $target = ''; if(isset($_GET['popup'])) { $target = ''; } return anchor($uri, ' ', array( 'target' => $target, 'class'=>'btn btn-danger btn-xs save_button', 'title'=>__('Save as Favourite for further analysis', 'wmvc_win'))); } } if ( ! function_exists('btn_block')) { /** * @deprecated 2.0 Use wmvc_btn_block() * @see wmvc_btn_block() */ function btn_block($uri, $confirm_question = FALSE, $title='') { $target = ''; if(isset($_GET['popup'])) { $target = '_blank'; } if($confirm_question) { return anchor($uri, ' ', array( 'target' => $target, 'title' => $title, 'onclick' => 'return confirm(\''.__('Are you sure?', 'wmvc_win').'\')', 'class'=>'btn btn-warning btn-xs block_button')); } else { return anchor($uri, ' ', array( 'target' => $target, 'title' => $title, 'class'=>'btn btn-warning btn-xs block_button')); } } } if ( ! function_exists('btn_view')) { /** * @deprecated 2.0 Use wmvc_btn_view() * @see wmvc_btn_view() */ function btn_view($uri, $confirm_question = FALSE, $title='') { if($confirm_question) { return anchor($uri, ' ', array( 'title' => $title, 'onclick' => 'return confirm(\''.__('Are you sure?', 'wmvc_win').'\')', 'class'=>'btn btn-info btn-xs')); } else { return anchor($uri, ' ', array( 'title' => $title, 'class'=>'btn btn-info btn-xs')); } } } if ( ! function_exists('btn_hide')) { /** * @deprecated 2.0 Use wmvc_btn_hide() * @see wmvc_btn_hide() */ function btn_hide($uri) { $target = ''; if(isset($_GET['popup'])) { $target = '_blank'; } return anchor($uri, ' ', array( 'target' => $target, 'class'=>'btn btn-default btn-xs', 'title'=>__('Define hide rules', 'wmvc_win'))); } } if ( ! function_exists('get_file_extension')) { /** * @deprecated 2.0 Use wmvc_get_file_extension() * @see wmvc_get_file_extension() */ function get_file_extension($filepath) { return substr($filepath, strrpos($filepath, '.')+1); } } if ( ! function_exists('character_hard_limiter')) { /** * @deprecated 2.0 Use wmvc_character_hard_limiter() * @see wmvc_character_hard_limiter() */ function character_hard_limiter($string, $max_len) { if(strlen($string)>$max_len) { return substr($string, 0, $max_len-3).'...'; } return $string; } } if ( ! function_exists('wmvc_echo_js')) { function wmvc_echo_js($str) { $str = str_replace("'", "\'", trim($str)); $str = str_replace('"', '\"', $str); echo $str; } } if ( ! function_exists('wmvc_js')) { function wmvc_js($str) { $str = str_replace("\\", "", trim($str)); $str = str_replace("'", "\'", trim($str)); $str = str_replace('"', '\"', $str); return $str; } } if ( ! function_exists('wmvc_dump')) { function wmvc_dump($var) { echo '
';
var_dump($var);
echo '';
}
}
if ( ! function_exists('wmvc_resolve_ip'))
{
function wmvc_resolve_ip($ip)
{
if($ip == 'DISABLED')
return $ip;
if (filter_var($ip, FILTER_VALIDATE_IP)) {
// $ip is a valid IP address"
} else {
return '';
}
if($ip == '::1')
{
return $ip.', local';
}
$str = ''.$ip.'';
return $str;
}
}
/**
* Stringify attributes for use in html tags.
*
* Helper function used to convert an array or object of
* attributes to a string
*
* @param mixed
* @return string
*/
if ( ! function_exists('wmvc_stringify_attributes'))
{
function wmvc_stringify_attributes($attributes, $js = FALSE)
{
if (is_object($attributes) && count($attributes) > 0)
{
$attributes = (array) $attributes;
}
if (is_array($attributes))
{
$atts = '';
if (count($attributes) === 0)
{
return $atts;
}
foreach ($attributes as $key => $val)
{
if ($js)
{
$atts .= $key.'='.$val.',';
}
else
{
$atts .= ' '.$key.'="'.$val.'"';
}
}
return rtrim($atts, ',');
}
elseif (is_string($attributes) && strlen($attributes) > 0)
{
return ' '.$attributes;
}
return $attributes;
}
}
if ( ! function_exists('wmvc_anchor'))
{
/**
* Anchor Link
*
* Creates an anchor based on the local URL.
*
* @param string the URL
* @param string the link title
* @param mixed any attributes
* @return string
*/
function wmvc_anchor($uri = '', $title = '', $attributes = '')
{
$title = (string) $title;
$site_url = is_array($uri)
? site_url($uri)
: (preg_match('#^(\w+:)?//#i', $uri) ? $uri : site_url($uri));
if ($title === '')
{
$title = $site_url;
}
if ($attributes !== '')
{
$attributes = wmvc_stringify_attributes($attributes);
}
return ''.wp_kses_post($title).'';
}
}
if ( ! function_exists('wmvc_btn_edit'))
{
function wmvc_btn_edit($uri)
{
return wmvc_anchor($uri, '', array('class'=>'btn btn-success btn-xs'));
}
}
if ( ! function_exists('wmvc_btn_read'))
{
function wmvc_btn_read($uri, $title=NULL)
{
if(empty($title))$title=__('Read', 'wmvc_win');
return wmvc_anchor($uri, ' '.esc_html($title), array('class'=>'btn btn-primary btn-xs'));
}
}
if ( ! function_exists('wmvc_btn_open'))
{
function wmvc_btn_open($uri, $target=NULL)
{
if($target === NULL)
$target = '_blank';
return wmvc_anchor($uri, '', array('class'=>'btn btn-primary btn-xs', 'target'=>esc_html($target), 'title'=>esc_html__('Open details', 'wmvc_win')));
}
}
if ( ! function_exists('wmvc_btn_open_ajax'))
{
function wmvc_btn_open_ajax($uri, $target=NULL)
{
if($target === NULL)
$target = '_blank';
return wmvc_anchor($uri, '', array('class'=>'btn btn-primary btn-xs popup-with-form-ajax', 'target'=>esc_html($target), 'title'=>esc_html__('Open details', 'wmvc_win')));
}
}
if ( ! function_exists('wmvc_btn_delete_noconfirm'))
{
function wmvc_btn_delete_noconfirm($uri)
{
return wmvc_anchor($uri, ' ', array('class'=>'btn btn-danger btn-xs delete_button'));
}
}
if ( ! function_exists('wmvc_btn_delete'))
{
function wmvc_btn_delete($uri, $confirm_question = TRUE, $title='')
{
$target = '';
if(isset($_GET['popup']))
{
$target = '';
}
if($confirm_question)
{
return wmvc_anchor($uri, ' ', array( 'target' => esc_html($target), 'title' => esc_html($title), 'onclick' => 'return confirm(\''.__('Are you sure?', 'wmvc_win').'\')', 'class'=>'btn btn-danger btn-xs delete_button action_confirm'));
}
else
{
return wmvc_anchor($uri, ' ', array( 'target' => esc_html($target), 'title' => esc_html($title), 'class'=>'btn btn-danger btn-xs delete_button'));
}
}
}
if ( ! function_exists('wmvc_btn_save'))
{
function wmvc_btn_save($uri, $empty = '-empty')
{
$target = '';
if(isset($_GET['popup']))
{
$target = '';
}
return wmvc_anchor($uri, ' ', array( 'target' => esc_html($target), 'class'=>'btn btn-danger btn-xs save_button', 'title'=>esc_html__('Save', 'wmvc_win')));
}
}
if ( ! function_exists('wmvc_btn_block'))
{
function wmvc_btn_block($uri, $confirm_question = FALSE, $title='')
{
$target = '';
if(isset($_GET['popup']))
{
$target = '_blank';
}
if($confirm_question)
{
return wmvc_anchor($uri, ' ', array( 'target' => esc_attr($target), 'title' => esc_html($title), 'onclick' => 'return confirm(\''.__('Are you sure?', 'wmvc_win').'\')', 'class'=>'btn btn-warning btn-xs block_button action_block'));
}
else
{
return wmvc_anchor($uri, ' ', array( 'target' => esc_attr($target), 'title' => esc_html($title), 'class'=>'btn btn-warning btn-xs block_button'));
}
}
}
if ( ! function_exists('wmvc_btn_view'))
{
function wmvc_btn_view($uri, $confirm_question = FALSE, $title='')
{
if($confirm_question)
{
return wmvc_anchor($uri, ' ', array( 'title' => esc_html($title), 'onclick' => 'return confirm(\''.__('Are you sure?', 'wmvc_win').'\')', 'class'=>'btn btn-info btn-xs'));
}
else
{
return wmvc_anchor($uri, ' ', array( 'title' => esc_html($title), 'class'=>'btn btn-info btn-xs'));
}
}
}
if ( ! function_exists('wmvc_btn_hide'))
{
function wmvc_btn_hide($uri)
{
$target = '';
if(isset($_GET['popup']))
{
$target = '_blank';
}
return wmvc_anchor($uri, ' ', array( 'target' => esc_attr($target), 'class'=>'btn btn-default btn-xs', 'title'=>esc_html__('Define hide rules', 'wmvc_win')));
}
}
if ( ! function_exists('wmvc_get_file_extension'))
{
function wmvc_get_file_extension($filepath)
{
return substr($filepath, strrpos($filepath, '.')+1);
}
}
if ( ! function_exists('wmvc_character_hard_limiter'))
{
function wmvc_character_hard_limiter($string, $max_len)
{
if(strlen($string)>$max_len)
{
return substr($string, 0, $max_len-3).'...';
}
return $string;
}
}
if(!function_exists('wmvc_count')) {
function wmvc_count($mixed='') {
$count = 0;
if(!empty($mixed) && (is_array($mixed))) {
$count = count($mixed);
} else if(!empty($mixed) && function_exists('is_countable') && version_compare(PHP_VERSION, '7.3', '<') && is_countable($mixed)) {
$count = count($mixed);
}
else if(!empty($mixed) && is_object($mixed)) {
$count = 1;
}
return $count;
}
}
function wmvc_is_user_in_role( $user, $role ) {
return in_array( $role, $user->roles );
}
function wmvc_is_logged_user()
{
$current_user = wp_get_current_user();
if ( 0 == $current_user->ID ) {
return false;
} else {
// Logged in.
return true;
}
}
function wmvc_get_current_user_role() {
if( is_user_logged_in() ) {
$user = wp_get_current_user();
$role = ( array ) $user->roles;
return $role[0];
} else {
return '';
}
}
function wmvc_user_in_role($role)
{
if(!wmvc_is_logged_user())
return false;
$current_user = wp_get_current_user();
return wmvc_is_user_in_role( $current_user, $role );
}
function wmvc_character_limiter($text, $limit)
{
if(is_array($text))
$text = 'Array( '. join(', ', $text).' )';
if(strlen($text) > $limit)
{
return substr($text, 0, $limit-4).'...';
}
return $text;
}
function wmvc_show_data($field_name, &$db_value = NULL, $default = '', $xss_clean = TRUE, $skip_post = FALSE)
{
if(!$skip_post && isset($_POST[$field_name]))
{
if($xss_clean === FALSE)
return stripslashes($_POST[$field_name]);
return wmvc_xss_clean(stripslashes($_POST[$field_name]));
}
if(is_array($db_value))
{
if(isset($db_value[$field_name]))
{
if($xss_clean === FALSE)
return $db_value[$field_name];
return wmvc_xss_clean($db_value[$field_name]);
}
else
{
return $default;
}
}
if(is_object($db_value))
{
if(isset($db_value->$field_name))
{
if($xss_clean === FALSE)
return $db_value->$field_name;
return wmvc_xss_clean($db_value->$field_name);
}
else
{
return $default;
}
}
if(!empty($db_value))
{
if($xss_clean === FALSE)
return $db_value;
return wmvc_xss_clean($db_value);
}
if($xss_clean === FALSE)
return $default;
return wmvc_xss_clean($default);
}
/*
*/
function wmvc_select_option($field_name, $options = array(), $selected = NULL, $extra=NULL, $empty_text = NULL, $empty_val = '')
{
$output = '';
return $output;
}
function wmvc_upload_media($field_name, $image_id)
{
static $media_element_counter = 0;
$media_element_counter++;
$img_field = $field_name.'_'.$media_element_counter;
wp_enqueue_script( 'wpmediaelement' );
wp_enqueue_media();
?>