';
$col2_fields = $this->get_fields_in_column( $subrow_fields, 2 );
- if ($col2_fields) {
- foreach ($col2_fields as $key => $data) {
-
- $data = apply_filters( "um_view_field_output_" . $data['type'], $data );
+ if ( $col2_fields ) {
+ foreach ( $col2_fields as $key => $data ) {
+ $data = $this->view_field_output( $data );
$output .= $this->view_field( $key, $data );
}
@@ -2891,11 +3734,10 @@ if ( ! class_exists( 'Fields' ) ) {
$output .= '
';
$col3_fields = $this->get_fields_in_column( $subrow_fields, 3 );
- if ($col3_fields) {
- foreach ($col3_fields as $key => $data) {
-
- $data = apply_filters( "um_view_field_output_" . $data['type'], $data );
+ if ( $col3_fields ) {
+ foreach ( $col3_fields as $key => $data ) {
+ $data = $this->view_field_output( $data );
$output .= $this->view_field( $key, $data );
}
diff --git a/includes/core/class-files.php b/includes/core/class-files.php
index a2534ef8..9b901442 100644
--- a/includes/core/class-files.php
+++ b/includes/core/class-files.php
@@ -5,847 +5,1217 @@ namespace um\core;
if ( ! defined( 'ABSPATH' ) ) exit;
if ( ! class_exists( 'Files' ) ) {
- class Files {
- var $upload_temp;
- var $upload_baseurl;
- var $upload_basedir;
-
- function __construct() {
-
- $this->setup_paths();
-
- $this->fonticon = array(
- 'pdf' => array('icon' => 'um-faicon-file-pdf-o', 'color' => '#D24D4D' ),
- 'txt' => array('icon' => 'um-faicon-file-text-o' ),
- 'csv' => array('icon' => 'um-faicon-file-text-o' ),
- 'doc' => array('icon' => 'um-faicon-file-text-o', 'color' => '#2C95D5' ),
- 'docx' => array('icon' => 'um-faicon-file-text-o', 'color' => '#2C95D5' ),
- 'odt' => array('icon' => 'um-faicon-file-text-o', 'color' => '#2C95D5' ),
- 'ods' => array('icon' => 'um-faicon-file-excel-o', 'color' => '#51BA6A' ),
- 'xls' => array('icon' => 'um-faicon-file-excel-o', 'color' => '#51BA6A' ),
- 'xlsx' => array('icon' => 'um-faicon-file-excel-o', 'color' => '#51BA6A' ),
- 'zip' => array('icon' => 'um-faicon-file-zip-o' ),
- 'rar' => array('icon' => 'um-faicon-file-zip-o' ),
- 'mp3' => array('icon' => 'um-faicon-file-audio-o' ),
- 'jpg' => array('icon' => 'um-faicon-picture-o' ),
- 'jpeg' => array('icon' => 'um-faicon-picture-o' ),
- 'png' => array('icon' => 'um-icon-image' ),
- 'gif' => array('icon' => 'um-icon-images' ),
- 'eps' => array('icon' => 'um-icon-images' ),
- 'psd' => array('icon' => 'um-icon-images' ),
- 'tif' => array('icon' => 'um-icon-image' ),
- 'tiff' => array('icon' => 'um-icon-image' ),
- );
-
- $this->default_file_fonticon = 'um-faicon-file-o';
-
- }
-
-
- function ajax_remove_file() {
- extract( $_REQUEST );
- $this->delete_file( $src );
- }
-
-
- function ajax_resize_image() {
- $output = 0;
-
- extract($_REQUEST);
-
- if ( !isset($src) || !isset($coord) ) die( __('Invalid parameters') );
-
- $coord_n = substr_count($coord, ",");
- if ( $coord_n != 3 ) die( __('Invalid coordinates') );
-
- $um_is_temp_image = um_is_temp_image( $src );
- if ( !$um_is_temp_image ) die( __('Invalid Image file') );
-
- $crop = explode(',', $coord );
- $crop = array_map('intval', $crop);
-
- $uri = UM()->files()->resize_image( $um_is_temp_image, $crop );
-
- // If you're updating a user
- if ( isset( $user_id ) && $user_id > 0 ) {
- $uri = UM()->files()->new_user_upload( $user_id, $um_is_temp_image, $key );
- }
-
- $output = $uri;
-
- delete_option( "um_cache_userdata_{$user_id}" );
-
- if(is_array($output)){ print_r($output); }else{ echo $output; } die;
- }
-
-
- /***
- *** @allowed image types
- ***/
- function allowed_image_types() {
-
- $array['png'] = 'PNG';
- $array['jpeg'] = 'JPEG';
- $array['jpg'] = 'JPG';
- $array['gif'] = 'GIF';
-
- $array = apply_filters('um_allowed_image_types', $array);
- return $array;
- }
-
- /***
- *** @allowed file types
- ***/
- function allowed_file_types() {
-
- $array['pdf'] = 'PDF';
- $array['txt'] = 'Text';
- $array['csv'] = 'CSV';
- $array['doc'] = 'DOC';
- $array['docx'] = 'DOCX';
- $array['odt'] = 'ODT';
- $array['ods'] = 'ODS';
- $array['xls'] = 'XLS';
- $array['xlsx'] = 'XLSX';
- $array['zip'] = 'ZIP';
- $array['rar'] = 'RAR';
- $array['mp3'] = 'MP3';
- $array['jpg'] = 'JPG';
- $array['jpeg'] = 'JPEG';
- $array['png'] = 'PNG';
- $array['gif'] = 'GIF';
- $array['eps'] = 'EPS';
- $array['psd'] = 'PSD';
- $array['tif'] = 'TIF';
- $array['tiff'] = 'TIFF';
-
- $array = apply_filters('um_allowed_file_types', $array);
- return $array;
- }
-
- /***
- *** @Get extension icon
- ***/
- function get_fonticon_by_ext( $extension ) {
- if ( isset( $this->fonticon[$extension]['icon'] ) ) {
- return $this->fonticon[$extension]['icon'];
- } else {
- return $this->default_file_fonticon;
- }
- }
-
- /***
- *** @Get extension icon background
- ***/
- function get_fonticon_bg_by_ext( $extension ) {
- if ( isset( $this->fonticon[$extension]['color'] ) ) {
- return $this->fonticon[$extension]['color'];
- } else {
- return '#666';
- }
- }
-
- /***
- *** @Setup upload directory
- ***/
- function setup_paths() {
-
- $this->upload_dir = wp_upload_dir();
-
- $this->upload_basedir = $this->upload_dir['basedir'] . '/ultimatemember/';
- $this->upload_baseurl = $this->upload_dir['baseurl'] . '/ultimatemember/';
-
- $this->upload_basedir = apply_filters( 'um_upload_basedir_filter', $this->upload_basedir );
- $this->upload_baseurl = apply_filters( 'um_upload_baseurl_filter', $this->upload_baseurl );
-
- // @note : is_ssl() doesn't work properly for some sites running with load balancers
- // Check the links for more info about this bug
- // https://codex.wordpress.org/Function_Reference/is_ssl
- // http://snippets.webaware.com.au/snippets/wordpress-is_ssl-doesnt-work-behind-some-load-balancers/
- if ( is_ssl() || stripos( get_option( 'siteurl' ), 'https://' ) !== false
- || ( isset( $_SERVER['HTTP_X_FORWARDED_PROTO'] ) && $_SERVER['HTTP_X_FORWARDED_PROTO'] == 'https' ) ) {
- $this->upload_baseurl = str_replace("http://", "https://", $this->upload_baseurl);
- }
-
- $this->upload_temp = $this->upload_basedir . 'temp/';
- $this->upload_temp_url = $this->upload_baseurl . 'temp/';
-
- if ( ! file_exists( $this->upload_basedir ) ) {
- $old = umask(0);
- @mkdir( $this->upload_basedir, 0755, true );
- umask( $old );
- }
-
- if ( ! file_exists( $this->upload_temp ) ) {
- $old = umask(0);
- @mkdir( $this->upload_temp , 0755, true );
- umask( $old );
- }
-
- }
-
- /***
- *** @Generate unique temp directory
- ***/
- function unique_dir(){
- $unique_number = UM()->validation()->generate();
- $array['dir'] = $this->upload_temp . $unique_number . '/';
- $array['url'] = $this->upload_temp_url . $unique_number . '/';
- return $array;
- }
-
- /***
- *** @get path only without file name
- ***/
- function path_only( $file ) {
- return trailingslashit( dirname( $file ) );
- }
-
- /***
- *** @fix image orientation
- ***/
- function fix_image_orientation($rotate, $source){
- if ( extension_loaded('exif') ){
- $exif = @exif_read_data($source);
-
- if (isset($exif['Orientation'])) {
- switch ($exif['Orientation']) {
- case 3:
- $rotate = imagerotate($rotate, 180, 0);
- break;
-
- case 6:
- $rotate = imagerotate($rotate, -90, 0);
- break;
-
- case 8:
- $rotate = imagerotate($rotate, 90, 0);
- break;
- }
- }
- }
- return $rotate;
- }
- /***
- *** @Process an image
- ***/
- function create_and_copy_image($source, $destination, $quality = 100) {
- $info = @getimagesize($source);
+ /**
+ * Class Files
+ * @package um\core
+ */
+ class Files {
- if ($info['mime'] == 'image/jpeg'){
- $image = imagecreatefromjpeg( $source );
+ /**
+ * @var
+ */
+ var $upload_temp;
- } else if ($info['mime'] == 'image/gif'){
- $image = imagecreatefromgif( $source );
+ /**
+ * @var
+ */
+ var $upload_baseurl;
+
+
+ /**
+ * @var
+ */
+ var $upload_basedir;
+
+
+ /**
+ * Files constructor.
+ */
+ function __construct() {
+
+ $this->setup_paths();
+
+ $this->fonticon = array(
+ 'pdf' => array('icon' => 'um-faicon-file-pdf-o', 'color' => '#D24D4D' ),
+ 'txt' => array('icon' => 'um-faicon-file-text-o' ),
+ 'csv' => array('icon' => 'um-faicon-file-text-o' ),
+ 'doc' => array('icon' => 'um-faicon-file-text-o', 'color' => '#2C95D5' ),
+ 'docx' => array('icon' => 'um-faicon-file-text-o', 'color' => '#2C95D5' ),
+ 'odt' => array('icon' => 'um-faicon-file-text-o', 'color' => '#2C95D5' ),
+ 'ods' => array('icon' => 'um-faicon-file-excel-o', 'color' => '#51BA6A' ),
+ 'xls' => array('icon' => 'um-faicon-file-excel-o', 'color' => '#51BA6A' ),
+ 'xlsx' => array('icon' => 'um-faicon-file-excel-o', 'color' => '#51BA6A' ),
+ 'zip' => array('icon' => 'um-faicon-file-zip-o' ),
+ 'rar' => array('icon' => 'um-faicon-file-zip-o' ),
+ 'mp3' => array('icon' => 'um-faicon-file-audio-o' ),
+ 'jpg' => array('icon' => 'um-faicon-picture-o' ),
+ 'jpeg' => array('icon' => 'um-faicon-picture-o' ),
+ 'png' => array('icon' => 'um-icon-image' ),
+ 'gif' => array('icon' => 'um-icon-images' ),
+ 'eps' => array('icon' => 'um-icon-images' ),
+ 'psd' => array('icon' => 'um-icon-images' ),
+ 'tif' => array('icon' => 'um-icon-image' ),
+ 'tiff' => array('icon' => 'um-icon-image' ),
+ );
+
+ $this->default_file_fonticon = 'um-faicon-file-o';
+ }
+
+
+ /**
+ * Remove file by AJAX
+ */
+ function ajax_remove_file() {
+ extract( $_REQUEST );
+ $this->delete_file( $src );
+ }
+
+
+ /**
+ * Resize image AJAX handler
+ */
+ function ajax_resize_image() {
+ $output = 0;
+
+ extract( $_REQUEST );
+
+ if ( !isset($src) || !isset($coord) ) die( __('Invalid parameters') );
+
+ $coord_n = substr_count($coord, ",");
+ if ( $coord_n != 3 ) die( __('Invalid coordinates') );
+
+ $um_is_temp_image = um_is_temp_image( $src );
+ if ( !$um_is_temp_image ) die( __('Invalid Image file') );
+
+ $crop = explode(',', $coord );
+ $crop = array_map('intval', $crop);
+
+ $uri = UM()->files()->resize_image( $um_is_temp_image, $crop );
+
+ // If you're updating a user
+ if ( isset( $user_id ) && $user_id > 0 ) {
+ $uri = UM()->files()->new_user_upload( $user_id, $um_is_temp_image, $key );
+ }
+
+ $output = $uri;
+
+ delete_option( "um_cache_userdata_{$user_id}" );
+
+ if(is_array($output)){ print_r($output); }else{ echo $output; } die;
+ }
+
+
+ /**
+ * Allowed image types
+ *
+ * @return array
+ */
+ function allowed_image_types() {
+ /**
+ * UM hook
+ *
+ * @type filter
+ * @title um_allowed_image_types
+ * @description Extend allowed image types
+ * @input_vars
+ * [{"var":"$types","type":"array","desc":"Image ext types"}]
+ * @change_log
+ * ["Since: 2.0"]
+ * @usage add_filter( 'um_allowed_image_types', 'function_name', 10, 1 );
+ * @example
+ *
+ */
+ return apply_filters( 'um_allowed_image_types', array(
+ 'png' => 'PNG',
+ 'jpeg' => 'JPEG',
+ 'jpg' => 'JPG',
+ 'gif' => 'GIF'
+ ) );
+ }
+
+
+ /**
+ * Allowed file types
+ *
+ * @return mixed
+ */
+ function allowed_file_types() {
+ /**
+ * UM hook
+ *
+ * @type filter
+ * @title um_allowed_file_types
+ * @description Extend allowed File types
+ * @input_vars
+ * [{"var":"$types","type":"array","desc":"Files ext types"}]
+ * @change_log
+ * ["Since: 2.0"]
+ * @usage add_filter( 'um_allowed_file_types', 'function_name', 10, 1 );
+ * @example
+ *
+ */
+ return apply_filters( 'um_allowed_file_types', array(
+ 'pdf' => 'PDF',
+ 'txt' => 'Text',
+ 'csv' => 'CSV',
+ 'doc' => 'DOC',
+ 'docx' => 'DOCX',
+ 'odt' => 'ODT',
+ 'ods' => 'ODS',
+ 'xls' => 'XLS',
+ 'xlsx' => 'XLSX',
+ 'zip' => 'ZIP',
+ 'rar' => 'RAR',
+ 'mp3' => 'MP3',
+ 'jpg' => 'JPG',
+ 'jpeg' => 'JPEG',
+ 'png' => 'PNG',
+ 'gif' => 'GIF',
+ 'eps' => 'EPS',
+ 'psd' => 'PSD',
+ 'tif' => 'TIF',
+ 'tiff' => 'TIFF',
+ ) );
+ }
+
+
+ /**
+ * Get extension icon
+ *
+ * @param $extension
+ *
+ * @return string
+ */
+ function get_fonticon_by_ext( $extension ) {
+ if ( isset( $this->fonticon[$extension]['icon'] ) ) {
+ return $this->fonticon[$extension]['icon'];
+ } else {
+ return $this->default_file_fonticon;
+ }
+ }
+
+
+ /**
+ * Get extension icon background
+ *
+ * @param $extension
+ *
+ * @return string
+ */
+ function get_fonticon_bg_by_ext( $extension ) {
+ if ( isset( $this->fonticon[$extension]['color'] ) ) {
+ return $this->fonticon[$extension]['color'];
+ } else {
+ return '#666';
+ }
+ }
+
+ /**
+ * Setup upload directory
+ */
+ function setup_paths() {
+
+ $this->upload_dir = wp_upload_dir();
+
+ $this->upload_basedir = $this->upload_dir['basedir'] . '/ultimatemember/';
+ $this->upload_baseurl = $this->upload_dir['baseurl'] . '/ultimatemember/';
+
+ /**
+ * UM hook
+ *
+ * @type filter
+ * @title um_upload_basedir_filter
+ * @description Change Uploads Basedir
+ * @input_vars
+ * [{"var":"$basedir","type":"string","desc":"Uploads basedir"}]
+ * @change_log
+ * ["Since: 2.0"]
+ * @usage add_filter( 'um_upload_basedir_filter', 'function_name', 10, 1 );
+ * @example
+ *
+ */
+ $this->upload_basedir = apply_filters( 'um_upload_basedir_filter', $this->upload_basedir );
+ /**
+ * UM hook
+ *
+ * @type filter
+ * @title um_upload_baseurl_filter
+ * @description Change Uploads Base URL
+ * @input_vars
+ * [{"var":"$baseurl","type":"string","desc":"Uploads base URL"}]
+ * @change_log
+ * ["Since: 2.0"]
+ * @usage add_filter( 'um_upload_baseurl_filter', 'function_name', 10, 1 );
+ * @example
+ *
+ */
+ $this->upload_baseurl = apply_filters( 'um_upload_baseurl_filter', $this->upload_baseurl );
+
+ // @note : is_ssl() doesn't work properly for some sites running with load balancers
+ // Check the links for more info about this bug
+ // https://codex.wordpress.org/Function_Reference/is_ssl
+ // http://snippets.webaware.com.au/snippets/wordpress-is_ssl-doesnt-work-behind-some-load-balancers/
+ if ( is_ssl() || stripos( get_option( 'siteurl' ), 'https://' ) !== false
+ || ( isset( $_SERVER['HTTP_X_FORWARDED_PROTO'] ) && $_SERVER['HTTP_X_FORWARDED_PROTO'] == 'https' ) ) {
+ $this->upload_baseurl = str_replace("http://", "https://", $this->upload_baseurl);
+ }
+
+ $this->upload_temp = $this->upload_basedir . 'temp/';
+ $this->upload_temp_url = $this->upload_baseurl . 'temp/';
+
+ if ( ! file_exists( $this->upload_basedir ) ) {
+ $old = umask(0);
+ @mkdir( $this->upload_basedir, 0755, true );
+ umask( $old );
+ }
+
+ if ( ! file_exists( $this->upload_temp ) ) {
+ $old = umask(0);
+ @mkdir( $this->upload_temp , 0755, true );
+ umask( $old );
+ }
+
+ }
+
+
+ /**
+ * Generate unique temp directory
+ *
+ * @return mixed
+ */
+ function unique_dir(){
+ $unique_number = UM()->validation()->generate();
+ $array['dir'] = $this->upload_temp . $unique_number . '/';
+ $array['url'] = $this->upload_temp_url . $unique_number . '/';
+ return $array;
+ }
+
+
+ /**
+ * Get path only without file name
+ *
+ * @param $file
+ *
+ * @return string
+ */
+ function path_only( $file ) {
+ return trailingslashit( dirname( $file ) );
+ }
+
+
+ /**
+ * Fix image orientation
+ *
+ * @param $rotate
+ * @param $source
+ *
+ * @return resource
+ */
+ function fix_image_orientation( $rotate, $source ) {
+ if ( extension_loaded('exif') ){
+ $exif = @exif_read_data( $source );
+
+ if (isset($exif['Orientation'])) {
+ switch ($exif['Orientation']) {
+ case 3:
+ $rotate = imagerotate($rotate, 180, 0);
+ break;
+
+ case 6:
+ $rotate = imagerotate($rotate, -90, 0);
+ break;
+
+ case 8:
+ $rotate = imagerotate($rotate, 90, 0);
+ break;
+ }
+ }
+ }
+ return $rotate;
+ }
+
+
+ /**
+ * Process an image
+ *
+ * @param $source
+ * @param $destination
+ * @param int $quality
+ *
+ * @return array
+ */
+ function create_and_copy_image($source, $destination, $quality = 100) {
+
+ $info = @getimagesize($source);
+
+ if ($info['mime'] == 'image/jpeg'){
+
+ $image = imagecreatefromjpeg( $source );
+
+ } else if ($info['mime'] == 'image/gif'){
- } else if ($info['mime'] == 'image/png'){
+ $image = imagecreatefromgif( $source );
- $image = imagecreatefrompng( $source );
- imagealphablending( $image, false );
- imagesavealpha( $image, true );
+ } else if ($info['mime'] == 'image/png'){
- }
+ $image = imagecreatefrompng( $source );
+ imagealphablending( $image, false );
+ imagesavealpha( $image, true );
- list($w, $h) = @getimagesize( $source );
- if ( $w > UM()->options()->get('image_max_width') ) {
+ }
+
+ list($w, $h) = @getimagesize( $source );
+ if ( $w > UM()->options()->get('image_max_width') ) {
- $ratio = round( $w / $h, 2 );
- $new_w = UM()->options()->get('image_max_width');
- $new_h = round( $new_w / $ratio, 2 );
+ $ratio = round( $w / $h, 2 );
+ $new_w = UM()->options()->get('image_max_width');
+ $new_h = round( $new_w / $ratio, 2 );
- if ( $info['mime'] == 'image/jpeg' || $info['mime'] == 'image/gif' ){
+ if ( $info['mime'] == 'image/jpeg' || $info['mime'] == 'image/gif' ){
- $image_p = imagecreatetruecolor( $new_w, $new_h );
- imagecopyresampled( $image_p, $image, 0, 0, 0, 0, $new_w, $new_h, $w, $h );
- $image_p = $this->fix_image_orientation( $image_p, $source );
+ $image_p = imagecreatetruecolor( $new_w, $new_h );
+ imagecopyresampled( $image_p, $image, 0, 0, 0, 0, $new_w, $new_h, $w, $h );
+ $image_p = $this->fix_image_orientation( $image_p, $source );
- }else if( $info['mime'] == 'image/png' ){
+ }else if( $info['mime'] == 'image/png' ){
- $srcImage = $image;
- $targetImage = imagecreatetruecolor( $new_w, $new_h );
- imagealphablending( $targetImage, false );
- imagesavealpha( $targetImage, true );
- imagecopyresampled( $targetImage, $srcImage, 0, 0, 0, 0, $new_w, $new_h, $w, $h );
+ $srcImage = $image;
+ $targetImage = imagecreatetruecolor( $new_w, $new_h );
+ imagealphablending( $targetImage, false );
+ imagesavealpha( $targetImage, true );
+ imagecopyresampled( $targetImage, $srcImage, 0, 0, 0, 0, $new_w, $new_h, $w, $h );
- }
+ }
- if ( $info['mime'] == 'image/jpeg' ){
- $has_copied = imagejpeg( $image_p, $destination, $quality );
- }else if ( $info['mime'] == 'image/gif' ){
- $has_copied = imagegif( $image_p, $destination );
- }else if ( $info['mime'] == 'image/png' ){
- $has_copied = imagepng( $targetImage, $destination, 0 ,PNG_ALL_FILTERS);
- }
+ if ( $info['mime'] == 'image/jpeg' ){
+ $has_copied = imagejpeg( $image_p, $destination, $quality );
+ }else if ( $info['mime'] == 'image/gif' ){
+ $has_copied = imagegif( $image_p, $destination );
+ }else if ( $info['mime'] == 'image/png' ){
+ $has_copied = imagepng( $targetImage, $destination, 0 ,PNG_ALL_FILTERS);
+ }
- $info['um_has_max_width'] = 'custom';
- $info['um_has_copied'] = $has_copied ? 'yes':'no';
+ $info['um_has_max_width'] = 'custom';
+ $info['um_has_copied'] = $has_copied ? 'yes':'no';
- } else {
+ } else {
- $image = $this->fix_image_orientation( $image, $source );
+ $image = $this->fix_image_orientation( $image, $source );
- if ( $info['mime'] == 'image/jpeg' ){
- $has_copied = imagejpeg( $image, $destination, $quality );
- }else if ( $info['mime'] == 'image/gif' ){
- $has_copied = imagegif( $image, $destination );
- }else if ( $info['mime'] == 'image/png' ){
- $has_copied = imagepng( $image , $destination , 0 ,PNG_ALL_FILTERS);
- }
+ if ( $info['mime'] == 'image/jpeg' ){
+ $has_copied = imagejpeg( $image, $destination, $quality );
+ }else if ( $info['mime'] == 'image/gif' ){
+ $has_copied = imagegif( $image, $destination );
+ }else if ( $info['mime'] == 'image/png' ){
+ $has_copied = imagepng( $image , $destination , 0 ,PNG_ALL_FILTERS);
+ }
- $info['um_has_max_width'] = 'default';
- $info['um_has_copied'] = $has_copied ? 'yes':'no';
- }
+ $info['um_has_max_width'] = 'default';
+ $info['um_has_copied'] = $has_copied ? 'yes':'no';
+ }
- return $info;
- }
+ return $info;
+ }
- /***
- *** @Process a file
- ***/
- function upload_temp_file( $source, $destination ) {
- move_uploaded_file( $source, $destination );
+ /**
+ * Process a file
+ *
+ * @param $source
+ * @param $destination
+ */
+ function upload_temp_file( $source, $destination ) {
+ move_uploaded_file( $source, $destination );
+ }
- }
- /***
- *** @Process a temp upload
- ***/
- function new_image_upload_temp( $source, $destination, $quality = 100 ){
+ /**
+ * Process a temp upload
+ *
+ * @param $source
+ * @param $destination
+ * @param int $quality
+ *
+ * @return string
+ */
+ function new_image_upload_temp( $source, $destination, $quality = 100 ){
- $unique_dir = $this->unique_dir();
+ $unique_dir = $this->unique_dir();
- $this->make_dir( $unique_dir['dir'] );
+ $this->make_dir( $unique_dir['dir'] );
- $info = $this->create_and_copy_image( $source, $unique_dir['dir'] . $destination, $quality );
+ $info = $this->create_and_copy_image( $source, $unique_dir['dir'] . $destination, $quality );
- $url = $unique_dir['url'] . $destination ;
+ $url = $unique_dir['url'] . $destination ;
- return $url;
+ return $url;
- }
+ }
- /***
- *** @Process a temp upload for files
- ***/
- function new_file_upload_temp( $source, $destination ){
- $unique_dir = $this->unique_dir();
+ /**
+ * Process a temp upload for files
+ *
+ * @param $source
+ * @param $destination
+ *
+ * @return string
+ */
+ function new_file_upload_temp( $source, $destination ){
- $this->make_dir( $unique_dir['dir'] );
+ $unique_dir = $this->unique_dir();
- $this->upload_temp_file( $source, $unique_dir['dir'] . $destination );
+ $this->make_dir( $unique_dir['dir'] );
- $url = $unique_dir['url'] . $destination;
+ $this->upload_temp_file( $source, $unique_dir['dir'] . $destination );
- return $url;
+ $url = $unique_dir['url'] . $destination;
- }
+ return $url;
- /***
- *** @Make a Folder
- ***/
- function make_dir( $dir ){
+ }
- $old = umask(0);
- @mkdir( $dir, 0755, true);
- umask( $old );
-
- }
-
- /***
- *** @Get extension by mime type
- ***/
- function get_extension_by_mime_type( $mime ){
- $split = explode('/', $mime );
- return $split[1];
- }
-
- /***
- *** @Get file data
- ***/
- function get_file_data( $file ){
-
- $array['size'] = filesize( $file );
-
- return $array;
- }
-
- /***
- *** @Get image data
- ***/
- function get_image_data( $file ){
-
- $array['size'] = filesize( $file );
-
- $array['image'] = @getimagesize( $file );
-
- if ( $array['image'] > 0 ) {
-
- $array['invalid_image'] = false;
-
- list($width, $height, $type, $attr) = @getimagesize( $file );
-
- $array['width'] = $width;
- $array['height'] = $height;
- $array['ratio'] = $width / $height;
-
- $array['extension'] = $this->get_extension_by_mime_type( $array['image']['mime'] );
-
- } else {
-
- $array['invalid_image'] = true;
-
- }
-
- return $array;
- }
-
- /***
- *** @Check image upload and handle errors
- ***/
- function check_image_upload( $file, $field ) {
- $error = null;
-
- $fileinfo = $this->get_image_data( $file );
- $data = UM()->fields()->get_field( $field );
-
- if ( $data == null ) {
- $data = apply_filters("um_custom_image_handle_{$field}", '' );
- if ( !$data ) {
- $error = __('This media type is not recognized.','ultimate-member');
- }
- }
-
- $data = apply_filters("um_image_handle_global__option", $data );
- $data = apply_filters("um_image_handle_{$field}__option", $data );
-
- if ( $fileinfo['invalid_image'] == true ) {
- $error = sprintf(__('Your image is invalid or too large!','ultimate-member') );
- } elseif ( isset( $data['allowed_types'] ) && !$this->in_array( $fileinfo['extension'], $data['allowed_types'] ) ) {
- $error = ( isset( $data['extension_error'] ) && !empty( $data['extension_error'] ) ) ? $data['extension_error'] : 'not allowed';
- } elseif ( isset($data['min_size']) && ( $fileinfo['size'] < $data['min_size'] ) ) {
- $error = $data['min_size_error'];
- } elseif ( isset($data['min_width']) && ( $fileinfo['width'] < $data['min_width'] ) ) {
- $error = sprintf(__('Your photo is too small. It must be at least %spx wide.','ultimate-member'), $data['min_width']);
- } elseif ( isset($data['min_height']) && ( $fileinfo['height'] < $data['min_height'] ) ) {
- $error = sprintf(__('Your photo is too small. It must be at least %spx wide.','ultimate-member'), $data['min_height']);
- }
-
- return $error;
- }
-
- /***
- *** @Check file upload and handle errors
- ***/
- function check_file_upload( $file, $extension, $field ) {
- $error = null;
-
- $fileinfo = $this->get_file_data( $file );
- $data = UM()->fields()->get_field( $field );
-
- if ( !$this->in_array( $extension, $data['allowed_types'] ) ) {
- $error = ( isset( $data['extension_error'] ) && !empty( $data['extension_error'] ) ) ? $data['extension_error'] : 'not allowed';
- } elseif ( isset($data['min_size']) && ( $fileinfo['size'] < $data['min_size'] ) ) {
- $error = $data['min_size_error'];
- }
-
- return $error;
- }
-
- /***
- *** @If a value exists in comma seperated list
- ***/
- function in_array( $value, $array ){
-
- if ( in_array( $value, explode(',', $array ) ) ){
- return true;
- }
-
- return false;
- }
-
- /***
- *** @This function will delete file upload from server
- ***/
- function delete_file( $src ) {
-
- if ( strstr( $src, '?' ) ) {
- $splitted = explode( '?', $src );
- $src = $splitted[0];
- }
-
- $is_temp = um_is_temp_upload( $src );
- if ( $is_temp ) {
- unlink( $is_temp );
- rmdir( dirname( $is_temp ) );
- } else {
- wp_die( __('Ultimate Member: Not a valid temp file','ultimate-member') );
- }
- }
-
- /***
- *** @delete a main user photo
- ***/
- function delete_core_user_photo( $user_id, $type ) {
-
- delete_user_meta( $user_id, $type );
-
- do_action("um_after_remove_{$type}", $user_id);
-
- $dir = $this->upload_basedir . $user_id . '/';
- $prefix = $type;
- chdir($dir);
- $matches = glob($prefix.'*',GLOB_MARK);
-
- if( is_array($matches) && !empty($matches)) {
- foreach($matches as $match) {
- if( is_file($dir.$match) ) unlink($dir.$match);
- }
- }
-
- if ( count(glob("$dir/*")) === 0) {
- rmdir( $dir );
- }
-
- }
-
- /***
- *** @resize a local image
- ***/
- function resize_image( $file, $crop ) {
-
- $targ_x1 = $crop[0];
- $targ_y1 = $crop[1];
- $targ_x2 = $crop[2];
- $targ_y2 = $crop[3];
-
-
- $info = @getimagesize( $file );
-
- if ( $info['mime'] == 'image/gif' ){
-
- $img_r = imagecreatefromgif( $file );
- $dst_r = imagecreatetruecolor( $targ_x2, $targ_y2 );
- imagecopy( $dst_r, $img_r, 0, 0, $targ_x1, $targ_y1, $targ_x2, $targ_y2 );
- imagegif( $dst_r, $this->path_only( $file ) . basename( $file ) );
-
- } else if ( $info['mime'] == 'image/png' ){
-
- $img_r = imagecreatefrompng( $file );
- $dst_r = imagecreatetruecolor( $targ_x2, $targ_y2 );
- imagealphablending( $dst_r, false);
- imagesavealpha( $dst_r, true);
- imagecopy( $dst_r, $img_r, 0, 0, $targ_x1, $targ_y1, $targ_x2, $targ_y2 );
- imagepng( $dst_r, $this->path_only( $file ) . basename( $file ) );
-
- }else{
-
- $img_r = imagecreatefromjpeg( $file );
- $dst_r = imagecreatetruecolor( $targ_x2, $targ_y2 );
- imagecopy( $dst_r, $img_r, 0, 0, $targ_x1, $targ_y1, $targ_x2, $targ_y2 );
- imagejpeg( $dst_r, $this->path_only( $file ) . basename( $file ), 100 );
-
- }
-
- $split = explode('/ultimatemember/temp/', $file );
- return $this->upload_temp_url . $split[1];
-
- }
-
- /***
- *** @make a user folder for uploads
- ***/
- function new_user( $user_id ) {
- if ( !file_exists( $this->upload_basedir . $user_id . '/' ) ) {
- $old = umask(0);
- @mkdir( $this->upload_basedir . $user_id . '/' , 0755, true);
- umask($old);
- }
- }
-
- /***
- *** @new user upload
- ***/
- function new_user_upload( $user_id, $source, $key ) {
-
- if( ! is_numeric( $user_id ) ){
- wp_die( __("Invalid user ID: ".json_encode( $user_id )." ",'ultimate-member') );
- }
-
- $user_id = trim( $user_id );
-
- // if he does not have uploads dir yet
- $this->new_user( $user_id );
-
- if ( is_user_logged_in() && ( get_current_user_id() != $user_id ) && ! UM()->roles()->um_user_can( 'can_edit_everyone' ) ) {
- wp_die( __( 'Unauthorized to do this attempt.', 'ultimate-member' ) );
- }
-
- $allow_frontend_image_uploads = apply_filters('um_allow_frontend_image_uploads', false, $user_id, $key );
-
- if ( $allow_frontend_image_uploads == false && !is_user_logged_in() && ( $key == 'profile_photo' || $key == 'cover_photo' ) ) {
- wp_die( __('Unauthorized to do this attempt.','ultimate-member') );
- }
-
- $ext = '.' . pathinfo($source, PATHINFO_EXTENSION);
-
- // copy & overwrite file
-
- if( in_array( $key , array('profile_photo','cover_photo') ) ){
- $filename = $key . $ext;
- $name = $key;
- }else{
- $filename = basename( $source );
- }
-
-
-
- if ( file_exists( $this->upload_basedir . $user_id . '/' . $filename ) ) {
- unlink( $this->upload_basedir . $user_id . '/' . $filename );
- }
- copy( $source, $this->upload_basedir . $user_id . '/' . $filename );
-
- $info = @getimagesize( $source );
-
- // thumbs
- if ( $key == 'profile_photo' ) {
-
- list($w, $h) = @getimagesize( $source );
-
-
- $sizes = UM()->options()->get( 'photo_thumb_sizes' );
- foreach( $sizes as $size ) {
-
- $ratio = round( $w / $h, 2 );
- $height = round( $size / $ratio, 2 );
-
- if ( file_exists( $this->upload_basedir . $user_id . '/' . $name . '-' . $size . $ext ) ) {
- unlink( $this->upload_basedir . $user_id . '/' . $name . '-' . $size . $ext );
- }
-
- if ( $size < $w ) {
-
- if ( $info['mime'] == 'image/jpeg' ){
- $thumb_s = imagecreatefromjpeg( $source );
- $thumb = imagecreatetruecolor( $size, $size );
- imagecopyresampled( $thumb, $thumb_s, 0, 0, 0, 0, $size, $size, $w, $h );
- imagejpeg( $thumb, $this->upload_basedir . $user_id . '/' . $name . '-' . $size . $ext, 100);
- imagejpeg( $thumb, $this->upload_basedir . $user_id . '/' . $name . $ext, 100);
- }else if ( $info['mime'] == 'image/png' ){
- $thumb_s = imagecreatefrompng( $source );
- $thumb = imagecreatetruecolor( $size, $size );
- imagealphablending( $thumb, false);
- imagesavealpha( $thumb, true);
- imagecopyresampled( $thumb, $thumb_s, 0, 0, 0, 0, $size, $size, $w, $h );
- imagepng( $thumb, $this->upload_basedir . $user_id . '/' . $name . '-' . $size . $ext );
- }else if ( $info['mime'] == 'image/gif' ){
- $thumb_s = imagecreatefromgif( $source );
- $thumb = imagecreatetruecolor( $size, $size );
- imagecopyresampled( $thumb, $thumb_s, 0, 0, 0, 0, $size, $size, $w, $h );
- imagegif( $thumb, $this->upload_basedir . $user_id . '/' . $name . '-' . $size . $ext);
- imagegif( $thumb, $this->upload_basedir . $user_id . '/' . $name . $ext);
- }
- }
-
- }
-
- // removes a synced profile photo
- delete_user_meta( $user_id, 'synced_profile_photo' );
-
- }else if ( $key == 'cover_photo' ) {
-
- list($w, $h) = @getimagesize( $source );
-
- $sizes = UM()->options()->get( 'cover_thumb_sizes' );
- foreach( $sizes as $size ) {
-
- $ratio = round( $w / $h, 2 );
- $height = round( $size / $ratio, 2 );
-
- if ( file_exists( $this->upload_basedir . $user_id . '/' . $name . '-' . $size . $ext ) ) {
- unlink( $this->upload_basedir . $user_id . '/' . $name . '-' . $size . $ext );
- }
-
- if ( $size < $w ) {
-
- if ( $info['mime'] == 'image/jpeg' ){
- $thumb = imagecreatetruecolor( $size, $height );
- $thumb_s = imagecreatefromjpeg( $source );
- imagecopyresampled( $thumb, $thumb_s, 0, 0, 0, 0, $size, $height, $w, $h );
- imagejpeg( $thumb, $this->upload_basedir . $user_id . '/' . $name . '-' . $size . $ext, 100);
- }else if ( $info['mime'] == 'image/png' ){
- $thumb_s = imagecreatefrompng( $source );
- $thumb = imagecreatetruecolor( $size, $height );
- imagealphablending( $thumb, false);
- imagesavealpha( $thumb, true);
- imagecopyresampled( $thumb, $thumb_s, 0, 0, 0, 0, $size, $height, $w, $h );
- imagepng( $thumb, $this->upload_basedir . $user_id . '/' . $name . '-' . $size . $ext );
- }else if ( $info['mime'] == 'image/gif' ){
- $thumb = imagecreatetruecolor( $size, $height );
- $thumb_s = imagecreatefromgif( $source );
- imagecopyresampled( $thumb, $thumb_s, 0, 0, 0, 0, $size, $height, $w, $h );
- imagegif( $thumb, $this->upload_basedir . $user_id . '/' . $name . '-' . $size . $ext);
- }
- }
-
- }
-
- }
-
- // clean up temp
- $dir = dirname( $source );
- unlink( $source );
- rmdir( $dir );
-
- // update user's meta
- do_action('um_before_upload_db_meta', $user_id, $key );
- do_action("um_before_upload_db_meta_{$key}", $user_id );
-
- update_user_meta( $user_id, $key, $filename );
-
- do_action('um_after_upload_db_meta', $user_id, $key );
- do_action("um_after_upload_db_meta_{$key}", $user_id );
-
- // the url of upload
- return $this->upload_baseurl . $user_id . '/' . $filename;
-
- }
-
- /***
- *** @Remove a directory
- ***/
- function remove_dir($dir) {
- if ( file_exists( $dir ) ) {
- foreach(glob($dir . '/*') as $file) {
- if(is_dir($file)) $this->remove_dir($file); else unlink($file);
- } rmdir($dir);
- }
- }
-
- /***
- *** @Format Bytes
- ****/
- function format_bytes( $size , $precision = 1 ) {
-
- $base = log($size, 1024);
- $suffixes = array('', 'kb', 'MB', 'GB', 'TB');
- $computed_size = round(pow(1024, $base - floor($base)), $precision);
- $unit = $suffixes[ floor($base) ];
-
- return $computed_size.' '.$unit;
-
- }
-
- function ajax_image_upload(){
- $ret['error'] = null;
- $ret = array();
-
- $id = $_POST['key'];
- $timestamp = $_POST['timestamp'];
- $nonce = $_POST['_wpnonce'];
-
- UM()->fields()->set_id = $_POST['set_id'];
- UM()->fields()->set_mode = $_POST['set_mode'];
-
- $um_image_upload_nonce = apply_filters("um_image_upload_nonce", true );
-
- if( $um_image_upload_nonce ){
- if ( ! wp_verify_nonce( $nonce, 'um_upload_nonce-'.$timestamp ) && is_user_logged_in() ) {
- // This nonce is not valid.
- $ret['error'] = 'Invalid nonce';
- die( json_encode( $ret ) );
- }
- }
-
- if(isset($_FILES[$id]['name'])) {
-
- if(!is_array($_FILES[$id]['name'])) {
-
- $temp = $_FILES[$id]["tmp_name"];
- $file = $id."-".$_FILES[$id]["name"];
- $file = sanitize_file_name($file);
- $ext = strtolower( pathinfo($file, PATHINFO_EXTENSION) );
-
- $error = UM()->files()->check_image_upload( $temp, $id );
- if ( $error ){
-
- $ret['error'] = $error;
-
- } else {
- $file = "stream_photo_".md5($file)."_".uniqid().".".$ext;
- $ret[ ] = UM()->files()->new_image_upload_temp( $temp, $file, UM()->options()->get('image_compression') );
-
- }
-
- }
-
- } else {
- $ret['error'] = __('A theme or plugin compatibility issue','ultimate-member');
- }
- echo json_encode($ret);
- exit;
- }
-
- function ajax_file_upload(){
- $ret['error'] = null;
- $ret = array();
-
- /* commented for enable download files on registration form
+ /**
+ * Make a Folder
+ *
+ * @param $dir
+ */
+ function make_dir( $dir ) {
+ $old = umask(0);
+ @mkdir( $dir, 0755, true);
+ umask( $old );
+ }
+
+
+ /**
+ * Get extension by mime type
+ *
+ * @param $mime
+ *
+ * @return mixed
+ */
+ function get_extension_by_mime_type( $mime ) {
+ $split = explode('/', $mime );
+ return $split[1];
+ }
+
+
+ /**
+ * Get file data
+ *
+ * @param $file
+ *
+ * @return mixed
+ */
+ function get_file_data( $file ) {
+ $array['size'] = filesize( $file );
+ return $array;
+ }
+
+
+ /**
+ * Get image data
+ *
+ * @param $file
+ *
+ * @return mixed
+ */
+ function get_image_data( $file ) {
+
+ $array['size'] = filesize( $file );
+
+ $array['image'] = @getimagesize( $file );
+
+ if ( $array['image'] > 0 ) {
+
+ $array['invalid_image'] = false;
+
+ list($width, $height, $type, $attr) = @getimagesize( $file );
+
+ $array['width'] = $width;
+ $array['height'] = $height;
+ $array['ratio'] = $width / $height;
+
+ $array['extension'] = $this->get_extension_by_mime_type( $array['image']['mime'] );
+
+ } else {
+
+ $array['invalid_image'] = true;
+
+ }
+
+ return $array;
+ }
+
+
+ /**
+ * Check image upload and handle errors
+ *
+ * @param $file
+ * @param $field
+ *
+ * @return null|string|void
+ */
+ function check_image_upload( $file, $field ) {
+ $error = null;
+
+ $fileinfo = $this->get_image_data( $file );
+ $data = UM()->fields()->get_field( $field );
+
+ if ( $data == null ) {
+ /**
+ * UM hook
+ *
+ * @type filter
+ * @title um_custom_image_handle_{$field}
+ * @description Custom image handle
+ * @input_vars
+ * [{"var":"$data","type":"array","desc":"Image Data"}]
+ * @change_log
+ * ["Since: 2.0"]
+ * @usage add_filter( 'um_custom_image_handle_{$field}', 'function_name', 10, 1 );
+ * @example
+ *
+ */
+ $data = apply_filters( "um_custom_image_handle_{$field}", array() );
+ if ( ! $data ) {
+ $error = __( 'This media type is not recognized.', 'ultimate-member' );
+ }
+ }
+
+ /**
+ * UM hook
+ *
+ * @type filter
+ * @title um_image_handle_global__option
+ * @description Custom image global handle
+ * @input_vars
+ * [{"var":"$data","type":"array","desc":"Image Data"}]
+ * @change_log
+ * ["Since: 2.0"]
+ * @usage add_filter( 'um_image_handle_global__option', 'function_name', 10, 1 );
+ * @example
+ *
+ */
+ $data = apply_filters("um_image_handle_global__option", $data );
+ /**
+ * UM hook
+ *
+ * @type filter
+ * @title um_image_handle_{$field}__option
+ * @description Custom image handle for each $field
+ * @input_vars
+ * [{"var":"$data","type":"array","desc":"Image Data"}]
+ * @change_log
+ * ["Since: 2.0"]
+ * @usage add_filter( 'um_image_handle_{$field}__option', 'function_name', 10, 1 );
+ * @example
+ *
+ */
+ $data = apply_filters( "um_image_handle_{$field}__option", $data );
+
+ if ( $fileinfo['invalid_image'] == true ) {
+ $error = sprintf(__('Your image is invalid or too large!','ultimate-member') );
+ } elseif ( isset( $data['allowed_types'] ) && !$this->in_array( $fileinfo['extension'], $data['allowed_types'] ) ) {
+ $error = ( isset( $data['extension_error'] ) && !empty( $data['extension_error'] ) ) ? $data['extension_error'] : 'not allowed';
+ } elseif ( isset($data['min_size']) && ( $fileinfo['size'] < $data['min_size'] ) ) {
+ $error = $data['min_size_error'];
+ } elseif ( isset($data['min_width']) && ( $fileinfo['width'] < $data['min_width'] ) ) {
+ $error = sprintf(__('Your photo is too small. It must be at least %spx wide.','ultimate-member'), $data['min_width']);
+ } elseif ( isset($data['min_height']) && ( $fileinfo['height'] < $data['min_height'] ) ) {
+ $error = sprintf(__('Your photo is too small. It must be at least %spx wide.','ultimate-member'), $data['min_height']);
+ }
+
+ return $error;
+ }
+
+
+ /**
+ * Check file upload and handle errors
+ *
+ * @param $file
+ * @param $extension
+ * @param $field
+ *
+ * @return null|string
+ */
+ function check_file_upload( $file, $extension, $field ) {
+ $error = null;
+
+ $fileinfo = $this->get_file_data( $file );
+ $data = UM()->fields()->get_field( $field );
+
+ if ( !$this->in_array( $extension, $data['allowed_types'] ) ) {
+ $error = ( isset( $data['extension_error'] ) && !empty( $data['extension_error'] ) ) ? $data['extension_error'] : 'not allowed';
+ } elseif ( isset($data['min_size']) && ( $fileinfo['size'] < $data['min_size'] ) ) {
+ $error = $data['min_size_error'];
+ }
+
+ return $error;
+ }
+
+
+ /**
+ * If a value exists in comma seperated list
+ *
+ * @param $value
+ * @param $array
+ *
+ * @return bool
+ */
+ function in_array( $value, $array ){
+
+ if ( in_array( $value, explode(',', $array ) ) ){
+ return true;
+ }
+
+ return false;
+ }
+
+
+ /**
+ * This function will delete file upload from server
+ *
+ * @param $src
+ */
+ function delete_file( $src ) {
+
+ if ( strstr( $src, '?' ) ) {
+ $splitted = explode( '?', $src );
+ $src = $splitted[0];
+ }
+
+ $is_temp = um_is_temp_upload( $src );
+ if ( $is_temp ) {
+ unlink( $is_temp );
+ rmdir( dirname( $is_temp ) );
+ } else {
+ wp_die( __('Ultimate Member: Not a valid temp file','ultimate-member') );
+ }
+ }
+
+
+ /**
+ * Delete a main user photo
+ *
+ * @param $user_id
+ * @param $type
+ */
+ function delete_core_user_photo( $user_id, $type ) {
+
+ delete_user_meta( $user_id, $type );
+
+ do_action("um_after_remove_{$type}", $user_id);
+
+ $dir = $this->upload_basedir . $user_id . '/';
+ $prefix = $type;
+ chdir($dir);
+ $matches = glob($prefix.'*',GLOB_MARK);
+
+ if( is_array($matches) && !empty($matches)) {
+ foreach($matches as $match) {
+ if( is_file($dir.$match) ) unlink($dir.$match);
+ }
+ }
+
+ if ( count(glob("$dir/*")) === 0) {
+ rmdir( $dir );
+ }
+
+ }
+
+
+ /**
+ * Resize a local image
+ *
+ * @param $file
+ * @param $crop
+ *
+ * @return string
+ */
+ function resize_image( $file, $crop ) {
+
+ $targ_x1 = $crop[0];
+ $targ_y1 = $crop[1];
+ $targ_x2 = $crop[2];
+ $targ_y2 = $crop[3];
+
+ $info = @getimagesize( $file );
+
+ if ( $info['mime'] == 'image/gif' ) {
+
+ $img_r = imagecreatefromgif( $file );
+ $dst_r = imagecreatetruecolor( $targ_x2, $targ_y2 );
+ imagecopy( $dst_r, $img_r, 0, 0, $targ_x1, $targ_y1, $targ_x2, $targ_y2 );
+ imagegif( $dst_r, $this->path_only( $file ) . basename( $file ) );
+
+ } elseif ( $info['mime'] == 'image/png' ) {
+
+ $img_r = imagecreatefrompng( $file );
+ $dst_r = imagecreatetruecolor( $targ_x2, $targ_y2 );
+ imagealphablending( $dst_r, false);
+ imagesavealpha( $dst_r, true);
+ imagecopy( $dst_r, $img_r, 0, 0, $targ_x1, $targ_y1, $targ_x2, $targ_y2 );
+ imagepng( $dst_r, $this->path_only( $file ) . basename( $file ) );
+
+ } else {
+
+ $img_r = imagecreatefromjpeg( $file );
+ $dst_r = imagecreatetruecolor( $targ_x2, $targ_y2 );
+ imagecopy( $dst_r, $img_r, 0, 0, $targ_x1, $targ_y1, $targ_x2, $targ_y2 );
+ imagejpeg( $dst_r, $this->path_only( $file ) . basename( $file ), 100 );
+
+ }
+
+ $split = explode('/ultimatemember/temp/', $file );
+ return $this->upload_temp_url . $split[1];
+ }
+
+
+ /**
+ * Make a user folder for uploads
+ *
+ * @param $user_id
+ */
+ function new_user( $user_id ) {
+ if ( !file_exists( $this->upload_basedir . $user_id . '/' ) ) {
+ $old = umask(0);
+ @mkdir( $this->upload_basedir . $user_id . '/' , 0755, true);
+ umask($old);
+ }
+ }
+
+
+ /**
+ * New user upload
+ *
+ * @param $user_id
+ * @param $source
+ * @param $key
+ *
+ * @return string
+ */
+ function new_user_upload( $user_id, $source, $key ) {
+
+ if( ! is_numeric( $user_id ) ){
+ wp_die( __("Invalid user ID: ".json_encode( $user_id )." ",'ultimate-member') );
+ }
+
+ $user_id = trim( $user_id );
+
+ // if he does not have uploads dir yet
+ $this->new_user( $user_id );
+
+ if ( is_user_logged_in() && ( get_current_user_id() != $user_id ) && ! UM()->roles()->um_user_can( 'can_edit_everyone' ) ) {
+ wp_die( __( 'Unauthorized to do this attempt.', 'ultimate-member' ) );
+ }
+
+ /**
+ * UM hook
+ *
+ * @type filter
+ * @title um_allow_frontend_image_uploads
+ * @description Allow Fronend Image uploads
+ * @input_vars
+ * [{"var":"$allow","type":"bool","desc":"Allow"},
+ * {"var":"$user_id","type":"int","desc":"User ID"},
+ * {"var":"$key","type":"string","desc":"Field Key"}]
+ * @change_log
+ * ["Since: 2.0"]
+ * @usage add_filter( 'um_allow_frontend_image_uploads', 'function_name', 10, 3 );
+ * @example
+ *
+ */
+ $allow_frontend_image_uploads = apply_filters( 'um_allow_frontend_image_uploads', false, $user_id, $key );
+
+ if ( $allow_frontend_image_uploads == false && ! is_user_logged_in() && ( $key == 'profile_photo' || $key == 'cover_photo' ) ) {
+ wp_die( __('Unauthorized to do this attempt.','ultimate-member') );
+ }
+
+ $ext = '.' . pathinfo($source, PATHINFO_EXTENSION);
+
+ // copy & overwrite file
+
+ if( in_array( $key , array('profile_photo','cover_photo') ) ){
+ $filename = $key . $ext;
+ $name = $key;
+ }else{
+ $filename = basename( $source );
+ }
+
+
+
+ if ( file_exists( $this->upload_basedir . $user_id . '/' . $filename ) ) {
+ unlink( $this->upload_basedir . $user_id . '/' . $filename );
+ }
+ copy( $source, $this->upload_basedir . $user_id . '/' . $filename );
+
+ $info = @getimagesize( $source );
+
+ // thumbs
+ if ( $key == 'profile_photo' ) {
+
+ list($w, $h) = @getimagesize( $source );
+
+
+ $sizes = UM()->options()->get( 'photo_thumb_sizes' );
+ foreach( $sizes as $size ) {
+
+ $ratio = round( $w / $h, 2 );
+ $height = round( $size / $ratio, 2 );
+
+ if ( file_exists( $this->upload_basedir . $user_id . '/' . $name . '-' . $size . $ext ) ) {
+ unlink( $this->upload_basedir . $user_id . '/' . $name . '-' . $size . $ext );
+ }
+
+ if ( $size < $w ) {
+
+ if ( $info['mime'] == 'image/jpeg' ){
+ $thumb_s = imagecreatefromjpeg( $source );
+ $thumb = imagecreatetruecolor( $size, $size );
+ imagecopyresampled( $thumb, $thumb_s, 0, 0, 0, 0, $size, $size, $w, $h );
+ imagejpeg( $thumb, $this->upload_basedir . $user_id . '/' . $name . '-' . $size . $ext, 100);
+ imagejpeg( $thumb, $this->upload_basedir . $user_id . '/' . $name . $ext, 100);
+ }else if ( $info['mime'] == 'image/png' ){
+ $thumb_s = imagecreatefrompng( $source );
+ $thumb = imagecreatetruecolor( $size, $size );
+ imagealphablending( $thumb, false);
+ imagesavealpha( $thumb, true);
+ imagecopyresampled( $thumb, $thumb_s, 0, 0, 0, 0, $size, $size, $w, $h );
+ imagepng( $thumb, $this->upload_basedir . $user_id . '/' . $name . '-' . $size . $ext );
+ }else if ( $info['mime'] == 'image/gif' ){
+ $thumb_s = imagecreatefromgif( $source );
+ $thumb = imagecreatetruecolor( $size, $size );
+ imagecopyresampled( $thumb, $thumb_s, 0, 0, 0, 0, $size, $size, $w, $h );
+ imagegif( $thumb, $this->upload_basedir . $user_id . '/' . $name . '-' . $size . $ext);
+ imagegif( $thumb, $this->upload_basedir . $user_id . '/' . $name . $ext);
+ }
+ }
+
+ }
+
+ // removes a synced profile photo
+ delete_user_meta( $user_id, 'synced_profile_photo' );
+
+ }else if ( $key == 'cover_photo' ) {
+
+ list($w, $h) = @getimagesize( $source );
+
+ $sizes = UM()->options()->get( 'cover_thumb_sizes' );
+ foreach( $sizes as $size ) {
+
+ $ratio = round( $w / $h, 2 );
+ $height = round( $size / $ratio, 2 );
+
+ if ( file_exists( $this->upload_basedir . $user_id . '/' . $name . '-' . $size . $ext ) ) {
+ unlink( $this->upload_basedir . $user_id . '/' . $name . '-' . $size . $ext );
+ }
+
+ if ( $size < $w ) {
+
+ if ( $info['mime'] == 'image/jpeg' ){
+ $thumb = imagecreatetruecolor( $size, $height );
+ $thumb_s = imagecreatefromjpeg( $source );
+ imagecopyresampled( $thumb, $thumb_s, 0, 0, 0, 0, $size, $height, $w, $h );
+ imagejpeg( $thumb, $this->upload_basedir . $user_id . '/' . $name . '-' . $size . $ext, 100);
+ }else if ( $info['mime'] == 'image/png' ){
+ $thumb_s = imagecreatefrompng( $source );
+ $thumb = imagecreatetruecolor( $size, $height );
+ imagealphablending( $thumb, false);
+ imagesavealpha( $thumb, true);
+ imagecopyresampled( $thumb, $thumb_s, 0, 0, 0, 0, $size, $height, $w, $h );
+ imagepng( $thumb, $this->upload_basedir . $user_id . '/' . $name . '-' . $size . $ext );
+ }else if ( $info['mime'] == 'image/gif' ){
+ $thumb = imagecreatetruecolor( $size, $height );
+ $thumb_s = imagecreatefromgif( $source );
+ imagecopyresampled( $thumb, $thumb_s, 0, 0, 0, 0, $size, $height, $w, $h );
+ imagegif( $thumb, $this->upload_basedir . $user_id . '/' . $name . '-' . $size . $ext);
+ }
+ }
+
+ }
+
+ }
+
+ // clean up temp
+ $dir = dirname( $source );
+ unlink( $source );
+ rmdir( $dir );
+
+ // update user's meta
+ do_action('um_before_upload_db_meta', $user_id, $key );
+ do_action("um_before_upload_db_meta_{$key}", $user_id );
+
+ update_user_meta( $user_id, $key, $filename );
+
+ do_action('um_after_upload_db_meta', $user_id, $key );
+ do_action("um_after_upload_db_meta_{$key}", $user_id );
+
+ // the url of upload
+ return $this->upload_baseurl . $user_id . '/' . $filename;
+
+ }
+
+
+ /**
+ * Remove a directory
+ *
+ * @param $dir
+ */
+ function remove_dir( $dir ) {
+ if ( file_exists( $dir ) ) {
+ foreach(glob($dir . '/*') as $file) {
+ if(is_dir($file)) $this->remove_dir($file); else unlink($file);
+ } rmdir($dir);
+ }
+ }
+
+
+ /**
+ * Format Bytes
+ *
+ * @param $size
+ * @param int $precision
+ *
+ * @return string
+ */
+ function format_bytes( $size , $precision = 1 ) {
+
+ $base = log($size, 1024);
+ $suffixes = array('', 'kb', 'MB', 'GB', 'TB');
+ $computed_size = round(pow(1024, $base - floor($base)), $precision);
+ $unit = $suffixes[ floor($base) ];
+
+ return $computed_size.' '.$unit;
+
+ }
+
+
+ /**
+ * Image upload by AJAX
+ */
+ function ajax_image_upload() {
+ $ret['error'] = null;
+ $ret = array();
+
+ $id = $_POST['key'];
+ $timestamp = $_POST['timestamp'];
+ $nonce = $_POST['_wpnonce'];
+
+ UM()->fields()->set_id = $_POST['set_id'];
+ UM()->fields()->set_mode = $_POST['set_mode'];
+
+ /**
+ * UM hook
+ *
+ * @type filter
+ * @title um_image_upload_nonce
+ * @description Change Image Upload nonce
+ * @input_vars
+ * [{"var":"$nonce","type":"bool","desc":"Nonce"}]
+ * @change_log
+ * ["Since: 2.0"]
+ * @usage
+ *
+ * @example
+ *
+ */
+ $um_image_upload_nonce = apply_filters("um_image_upload_nonce", true );
+
+ if( $um_image_upload_nonce ){
+ if ( ! wp_verify_nonce( $nonce, 'um_upload_nonce-'.$timestamp ) && is_user_logged_in() ) {
+ // This nonce is not valid.
+ $ret['error'] = 'Invalid nonce';
+ die( json_encode( $ret ) );
+ }
+ }
+
+ if(isset($_FILES[$id]['name'])) {
+
+ if(!is_array($_FILES[$id]['name'])) {
+
+ $temp = $_FILES[$id]["tmp_name"];
+ $file = $id."-".$_FILES[$id]["name"];
+ $file = sanitize_file_name($file);
+ $ext = strtolower( pathinfo($file, PATHINFO_EXTENSION) );
+
+ $error = UM()->files()->check_image_upload( $temp, $id );
+ if ( $error ){
+
+ $ret['error'] = $error;
+
+ } else {
+ $file = "stream_photo_".md5($file)."_".uniqid().".".$ext;
+ $ret[ ] = UM()->files()->new_image_upload_temp( $temp, $file, UM()->options()->get('image_compression') );
+
+ }
+
+ }
+
+ } else {
+ $ret['error'] = __('A theme or plugin compatibility issue','ultimate-member');
+ }
+ echo json_encode($ret);
+ exit;
+ }
+
+ function ajax_file_upload(){
+ $ret['error'] = null;
+ $ret = array();
+
+ /* commented for enable download files on registration form
* if ( ! is_user_logged_in() ) {
$ret['error'] = 'Invalid user';
die( json_encode( $ret ) );
}*/
- $nonce = $_POST['_wpnonce'];
- $id = $_POST['key'];
- $timestamp = $_POST['timestamp'];
+ $nonce = $_POST['_wpnonce'];
+ $id = $_POST['key'];
+ $timestamp = $_POST['timestamp'];
- UM()->fields()->set_id = $_POST['set_id'];
- UM()->fields()->set_mode = $_POST['set_mode'];
+ UM()->fields()->set_id = $_POST['set_id'];
+ UM()->fields()->set_mode = $_POST['set_mode'];
- $um_file_upload_nonce = apply_filters("um_file_upload_nonce", true );
+ /**
+ * UM hook
+ *
+ * @type filter
+ * @title um_file_upload_nonce
+ * @description Change File Upload nonce
+ * @input_vars
+ * [{"var":"$nonce","type":"bool","desc":"Nonce"}]
+ * @change_log
+ * ["Since: 2.0"]
+ * @usage
+ *
+ * @example
+ *
+ */
+ $um_file_upload_nonce = apply_filters("um_file_upload_nonce", true );
- if( $um_file_upload_nonce ){
- if ( ! wp_verify_nonce( $nonce, 'um_upload_nonce-'.$timestamp ) && is_user_logged_in()) {
- // This nonce is not valid.
- $ret['error'] = 'Invalid nonce';
- die( json_encode( $ret ) );
- }
- }
+ if ( $um_file_upload_nonce ) {
+ if ( ! wp_verify_nonce( $nonce, 'um_upload_nonce-'.$timestamp ) && is_user_logged_in()) {
+ // This nonce is not valid.
+ $ret['error'] = 'Invalid nonce';
+ die( json_encode( $ret ) );
+ }
+ }
- if(isset($_FILES[$id]['name'])) {
+ if(isset($_FILES[$id]['name'])) {
- if(!is_array($_FILES[$id]['name'])) {
+ if(!is_array($_FILES[$id]['name'])) {
- $temp = $_FILES[$id]["tmp_name"];
- $file = apply_filters('um_upload_file_name',$id."-".$_FILES[$id]["name"],$id,$_FILES[$id]["name"]);
- $file = sanitize_file_name($file);
- $extension = strtolower( pathinfo($file, PATHINFO_EXTENSION) );
+ $temp = $_FILES[$id]["tmp_name"];
+ /**
+ * UM hook
+ *
+ * @type filter
+ * @title um_upload_file_name
+ * @description Change File Upload nonce
+ * @input_vars
+ * [{"var":"$filename","type":"string","desc":"Filename"},
+ * {"var":"$id","type":"int","desc":"ID"},
+ * {"var":"$name","type":"string","desc":"Name"}]
+ * @change_log
+ * ["Since: 2.0"]
+ * @usage
+ *
+ * @example
+ *
+ */
+ $file = apply_filters( 'um_upload_file_name', $id . "-" . $_FILES[$id]["name"], $id, $_FILES[$id]["name"] );
+ $file = sanitize_file_name($file);
+ $extension = strtolower( pathinfo($file, PATHINFO_EXTENSION) );
- $error = UM()->files()->check_file_upload( $temp, $extension, $id );
- if ( $error ){
- $ret['error'] = $error;
- } else {
- $ret[] = UM()->files()->new_file_upload_temp( $temp, $file );
- $ret['icon'] = UM()->files()->get_fonticon_by_ext( $extension );
- $ret['icon_bg'] = UM()->files()->get_fonticon_bg_by_ext( $extension );
- $ret['filename'] = $file;
- }
+ $error = UM()->files()->check_file_upload( $temp, $extension, $id );
+ if ( $error ){
+ $ret['error'] = $error;
+ } else {
+ $ret[] = UM()->files()->new_file_upload_temp( $temp, $file );
+ $ret['icon'] = UM()->files()->get_fonticon_by_ext( $extension );
+ $ret['icon_bg'] = UM()->files()->get_fonticon_bg_by_ext( $extension );
+ $ret['filename'] = $file;
+ }
- }
+ }
- } else {
- $ret['error'] = __('A theme or plugin compatibility issue','ultimate-member');
- }
- echo json_encode($ret);
- exit;
- }
- }
+ } else {
+ $ret['error'] = __('A theme or plugin compatibility issue','ultimate-member');
+ }
+ echo json_encode($ret);
+ exit;
+ }
+ }
}
\ No newline at end of file
diff --git a/includes/core/class-form.php b/includes/core/class-form.php
index 6336ff9a..72ad0b1c 100644
--- a/includes/core/class-form.php
+++ b/includes/core/class-form.php
@@ -52,6 +52,27 @@ if ( ! class_exists( 'Form' ) ) {
$form_fields = UM()->fields()->get_fields();
$arr_options['fields'] = $form_fields;
+ /**
+ * UM hook
+ *
+ * @type filter
+ * @title um_ajax_select_options__debug_mode
+ * @description Activate debug mode for AJAX select options
+ * @input_vars
+ * [{"var":"$debug_mode","type":"bool","desc":"Enable Debug mode"}]
+ * @change_log
+ * ["Since: 2.0"]
+ * @usage
+ *
+ * @example
+ *
+ */
$debug = apply_filters('um_ajax_select_options__debug_mode', false );
if( $debug ){
$arr_options['debug'] = array(
@@ -100,16 +121,36 @@ if ( ! class_exists( 'Form' ) ) {
}
- /**
+ /**
* Appends field errors
* @param string $key
* @param string $error
*/
function add_error( $key, $error ) {
if ( ! isset( $this->errors[ $key ] ) ){
-
- $error = apply_filters('um_submit_form_error', $error , $key );
-
+ /**
+ * UM hook
+ *
+ * @type filter
+ * @title um_submit_form_error
+ * @description Change error text on submit form
+ * @input_vars
+ * [{"var":"$error","type":"string","desc":"Error String"},
+ * {"var":"$key","type":"string","desc":"Error Key"}]
+ * @change_log
+ * ["Since: 2.0"]
+ * @usage
+ *
+ * @example
+ *
+ */
+ $error = apply_filters( 'um_submit_form_error', $error, $key );
$this->errors[ $key ] = $error;
}
}
@@ -158,9 +199,29 @@ if ( ! class_exists( 'Form' ) ) {
if ( $this->form_status == 'publish' ) {
-
/* save entire form as global */
- $this->post_form = apply_filters('um_submit_post_form' ,$_POST );
+ /**
+ * UM hook
+ *
+ * @type filter
+ * @title um_submit_post_form
+ * @description Change submitted data on form submit
+ * @input_vars
+ * [{"var":"$data","type":"array","desc":"Submitted data"}]
+ * @change_log
+ * ["Since: 2.0"]
+ * @usage
+ *
+ * @example
+ *
+ */
+ $this->post_form = apply_filters( 'um_submit_post_form', $_POST );
$this->post_form = $this->beautify( $this->post_form );
@@ -220,6 +281,28 @@ if ( ! class_exists( 'Form' ) ) {
}
+ /**
+ * UM hook
+ *
+ * @type filter
+ * @title um_submit_form_data
+ * @description Change submitted data on form submit
+ * @input_vars
+ * [{"var":"$data","type":"array","desc":"Submitted data"},
+ * {"var":"$mode","type":"string","desc":"Form mode"}]
+ * @change_log
+ * ["Since: 2.0"]
+ * @usage
+ *
+ * @example
+ *
+ */
$this->post_form = apply_filters( 'um_submit_form_data', $this->post_form, $this->post_form['mode'] );
/* Continue based on form mode - pre-validation */
diff --git a/includes/core/class-mail.php b/includes/core/class-mail.php
index 932e5339..19a0b0a7 100644
--- a/includes/core/class-mail.php
+++ b/includes/core/class-mail.php
@@ -20,6 +20,27 @@ if ( ! class_exists( 'Mail' ) ) {
function init_paths() {
+ /**
+ * UM hook
+ *
+ * @type filter
+ * @title um_email_templates_path_by_slug
+ * @description Extend email templates path
+ * @input_vars
+ * [{"var":"$paths","type":"array","desc":"Email slug -> Template Path"}]
+ * @change_log
+ * ["Since: 2.0"]
+ * @usage
+ *
+ * @example
+ *
+ */
$this->path_by_slug = apply_filters( 'um_email_templates_path_by_slug', $this->path_by_slug );
}
@@ -58,6 +79,28 @@ if ( ! class_exists( 'Mail' ) ) {
$this->attachments = null;
$this->headers = 'From: '. UM()->options()->get('mail_from') .' <'. UM()->options()->get('mail_from_addr') .'>' . "\r\n";
+ /**
+ * UM hook
+ *
+ * @type filter
+ * @title um_email_send_subject
+ * @description Change email notification subject
+ * @input_vars
+ * [{"var":"$subject","type":"string","desc":"Subject"},
+ * {"var":"$key","type":"string","desc":"Template Key"}]
+ * @change_log
+ * ["Since: 2.0"]
+ * @usage
+ *
+ * @example
+ *
+ */
$subject = apply_filters( 'um_email_send_subject', UM()->options()->get( $template . '_sub' ), $template );
$this->subject = um_convert_tags( $subject , $args );
@@ -78,6 +121,29 @@ if ( ! class_exists( 'Mail' ) ) {
function get_email_template( $slug, $args = array() ) {
$located = $this->locate_template( $slug );
+ /**
+ * UM hook
+ *
+ * @type filter
+ * @title um_email_template_path
+ * @description Change email template location
+ * @input_vars
+ * [{"var":"$located","type":"string","desc":"Template Location"},
+ * {"var":"$slug","type":"string","desc":"Template Key"},
+ * {"var":"$args","type":"array","desc":"Template settings"}]
+ * @change_log
+ * ["Since: 2.0"]
+ * @usage
+ *
+ * @example
+ *
+ */
$located = apply_filters( 'um_email_template_path', $located, $slug, $args );
if ( ! file_exists( $located ) ) {
@@ -109,13 +175,63 @@ if ( ! class_exists( 'Mail' ) ) {
if ( UM()->options()->get( 'email_html' ) ) {
+ /**
+ * UM hook
+ *
+ * @type filter
+ * @title um_email_template_html_formatting
+ * @description Change email notification template header
+ * @input_vars
+ * [{"var":"$header","type":"string","desc":"Email notification header. '' by default"},
+ * {"var":"$slug","type":"string","desc":"Template Key"},
+ * {"var":"$args","type":"array","desc":"Template settings"}]
+ * @change_log
+ * ["Since: 2.0"]
+ * @usage
+ *
+ * @example
+ *
+ */
echo apply_filters( 'um_email_template_html_formatting', '', $slug, $args );
- do_action( 'um_before_email_template_body', $slug, $args ); ?>
+ do_action( 'um_before_email_template_body', $slug, $args );
- >
+ /**
+ * UM hook
+ *
+ * @type filter
+ * @title um_email_template_body_attrs
+ * @description Change email notification template body additional attributes
+ * @input_vars
+ * [{"var":"$body_atts","type":"string","desc":"Email notification body attributes"},
+ * {"var":"$slug","type":"string","desc":"Template Key"},
+ * {"var":"$args","type":"array","desc":"Template settings"}]
+ * @change_log
+ * ["Since: 2.0"]
+ * @usage
+ *
+ * @example
+ *
+ */
+ $body_attrs = apply_filters( 'um_email_template_body_attrs', 'style="background: #f2f2f2;-webkit-font-smoothing: antialiased;-moz-osx-font-smoothing: grayscale;"', $slug, $args );
+ ?>
- get_email_template( $slug, $args ); ?>
+
+ >
+
+ get_email_template( $slug, $args ); ?>
@@ -153,10 +269,57 @@ if ( ! class_exists( 'Mail' ) ) {
}
// Return what we found.
+ /**
+ * UM hook
+ *
+ * @type filter
+ * @title um_locate_email_template
+ * @description Change email notification template path
+ * @input_vars
+ * [{"var":"$template","type":"string","desc":"Template Path"},
+ * {"var":"$template_name","type":"string","desc":"Template Name"}]
+ * @change_log
+ * ["Since: 2.0"]
+ * @usage
+ *
+ * @example
+ *
+ */
return apply_filters( 'um_locate_email_template', $template, $template_name );
}
+ function get_template_filename( $template_name ) {
+ /**
+ * UM hook
+ *
+ * @type filter
+ * @title um_change_email_template_file
+ * @description Change email notification template path
+ * @input_vars
+ * [{"var":"$template_name","type":"string","desc":"Template Name"}]
+ * @change_log
+ * ["Since: 2.0"]
+ * @usage
+ *
+ * @example
+ *
+ */
+ return apply_filters( 'um_change_email_template_file', $template_name );
+ }
+
/**
* Locate a template and return the path for inclusion.
*
@@ -166,7 +329,7 @@ if ( ! class_exists( 'Mail' ) ) {
* @return string
*/
function template_in_theme( $template_name, $html = false ) {
- $template_name_file = apply_filters( 'um_change_email_template_file', $template_name );
+ $template_name_file = $this->get_template_filename( $template_name );
$ext = ! $html ? '.php' : '.html';
// check if there is template at theme folder
@@ -190,7 +353,7 @@ if ( ! class_exists( 'Mail' ) ) {
*/
function get_template_file( $location, $template_name, $html = false ) {
$template_path = '';
- $template_name_file = apply_filters( 'um_change_email_template_file', $template_name );
+ $template_name_file = $this->get_template_filename( $template_name );
$ext = ! $html ? '.php' : '.html';
diff --git a/includes/core/class-members.php b/includes/core/class-members.php
index 58700fe5..fda7df95 100644
--- a/includes/core/class-members.php
+++ b/includes/core/class-members.php
@@ -73,20 +73,127 @@ if ( ! class_exists( 'Members' ) ) {
if ( isset( $fields[ $filter ] ) ) {
$attrs = $fields[ $filter ];
} else {
- $attrs = apply_filters("um_custom_search_field_{$filter}", array() );
+ /**
+ * UM hook
+ *
+ * @type filter
+ * @title um_custom_search_field_{$filter}
+ * @description Custom search settings by $filter
+ * @input_vars
+ * [{"var":"$settings","type":"array","desc":"Search Settings"}]
+ * @change_log
+ * ["Since: 2.0"]
+ * @usage
+ *
+ * @example
+ *
+ */
+ $attrs = apply_filters( "um_custom_search_field_{$filter}", array() );
}
// additional filter for search field attributes
- $attrs = apply_filters("um_search_field_{$filter}", $attrs);
+ /**
+ * UM hook
+ *
+ * @type filter
+ * @title um_search_field_{$filter}
+ * @description Extend search settings by $filter
+ * @input_vars
+ * [{"var":"$settings","type":"array","desc":"Search Settings"}]
+ * @change_log
+ * ["Since: 2.0"]
+ * @usage
+ *
+ * @example
+ *
+ */
+ $attrs = apply_filters( "um_search_field_{$filter}", $attrs );
$type = UM()->builtin()->is_dropdown_field( $filter, $attrs ) ? 'select' : 'text';
+
+ /**
+ * UM hook
+ *
+ * @type filter
+ * @title um_search_field_type
+ * @description Change search field type
+ * @input_vars
+ * [{"var":"$type","type":"string","desc":"Search field type"},
+ * {"var":"$settings","type":"array","desc":"Search Settings"}]
+ * @change_log
+ * ["Since: 2.0"]
+ * @usage
+ *
+ * @example
+ *
+ */
$type = apply_filters( 'um_search_field_type', $type, $attrs );
- // filter all search fields
+ /**
+ * UM hook
+ *
+ * @type filter
+ * @title um_search_fields
+ * @description Filter all search fields
+ * @input_vars
+ * [{"var":"$settings","type":"array","desc":"Search Fields"}]
+ * @change_log
+ * ["Since: 2.0"]
+ * @usage
+ *
+ * @example
+ *
+ */
$attrs = apply_filters( 'um_search_fields', $attrs );
- if ( $type == 'select' )
+ if ( $type == 'select' ) {
+ /**
+ * UM hook
+ *
+ * @type filter
+ * @title um_search_select_fields
+ * @description Filter all search fields for select field type
+ * @input_vars
+ * [{"var":"$settings","type":"array","desc":"Search Fields"}]
+ * @change_log
+ * ["Since: 2.0"]
+ * @usage
+ *
+ * @example
+ *
+ */
$attrs = apply_filters( 'um_search_select_fields', $attrs );
+ }
switch ( $type ) {
@@ -181,10 +288,31 @@ if ( ! class_exists( 'Members' ) ) {
* @var $profiles_per_page
* @var $profiles_per_page_mobile
*/
- extract($args);
+ extract( $args );
- $query_args = array();
- $query_args = apply_filters( 'um_prepare_user_query_args', $query_args, $args );
+ /**
+ * UM hook
+ *
+ * @type filter
+ * @title um_prepare_user_query_args
+ * @description Extend member directory query arguments
+ * @input_vars
+ * [{"var":"$query_args","type":"array","desc":"Members Query Arguments"},
+ * {"var":"$directory_settings","type":"array","desc":"Member Directory Settings"}]
+ * @change_log
+ * ["Since: 2.0"]
+ * @usage
+ *
+ * @example
+ *
+ */
+ $query_args = apply_filters( 'um_prepare_user_query_args', array(), $args );
// Prepare for BIG SELECT query
$wpdb->query('SET SQL_BIG_SELECTS=1');
@@ -318,8 +446,28 @@ if ( ! class_exists( 'Members' ) ) {
}
- return apply_filters('um_prepare_user_results_array', $array );
-
+ /**
+ * UM hook
+ *
+ * @type filter
+ * @title um_prepare_user_results_array
+ * @description Extend member directory query result
+ * @input_vars
+ * [{"var":"$result","type":"array","desc":"Members Query Result"}]
+ * @change_log
+ * ["Since: 2.0"]
+ * @usage
+ *
+ * @example
+ *
+ */
+ return apply_filters( 'um_prepare_user_results_array', $array );
}
diff --git a/includes/core/class-options.php b/includes/core/class-options.php
index 8b441a0a..24507d4e 100644
--- a/includes/core/class-options.php
+++ b/includes/core/class-options.php
@@ -32,8 +32,30 @@ if ( ! class_exists( 'Options' ) ) {
* @return mixed|string|void
*/
function get( $option_id ) {
- if ( isset( $this->options[ $option_id ] ) )
+ if ( isset( $this->options[ $option_id ] ) ) {
+ /**
+ * UM hook
+ *
+ * @type filter
+ * @title um_get_option_filter__{$option_id}
+ * @description Change UM option on get by $option_id
+ * @input_vars
+ * [{"var":"$option","type":"array","desc":"Option Value"}]
+ * @change_log
+ * ["Since: 2.0"]
+ * @usage
+ *
+ * @example
+ *
+ */
return apply_filters( "um_get_option_filter__{$option_id}", $this->options[ $option_id ] );
+ }
switch ( $option_id ) {
case 'site_name':
@@ -90,5 +112,38 @@ if ( ! class_exists( 'Options' ) ) {
return $settings_defaults[ $option_id ];
}
+
+ /**
+ * Get core page ID
+ *
+ * @param string $key
+ *
+ * @return mixed|void
+ */
+ function get_core_page_id( $key ) {
+ /**
+ * UM hook
+ *
+ * @type filter
+ * @title um_core_page_id_filter
+ * @description Change UM page slug
+ * @input_vars
+ * [{"var":"$slug","type":"array","desc":"UM page slug"}]
+ * @change_log
+ * ["Since: 2.0"]
+ * @usage
+ *
+ * @example
+ *
+ */
+ return apply_filters( 'um_core_page_id_filter', 'core_' . $key );
+ }
+
}
}
\ No newline at end of file
diff --git a/includes/core/class-password.php b/includes/core/class-password.php
index 3fe33278..c30d1e6c 100644
--- a/includes/core/class-password.php
+++ b/includes/core/class-password.php
@@ -132,7 +132,28 @@ if ( ! class_exists( 'Password' ) ) {
$classes .= ' um-viewing';
}
- $classes = apply_filters('um_form_official_classes__hook', $classes);
+ /**
+ * UM hook
+ *
+ * @type filter
+ * @title um_form_official_classes__hook
+ * @description Change form additional classes
+ * @input_vars
+ * [{"var":"$classes","type":"string","desc":"Form additional classes"}]
+ * @change_log
+ * ["Since: 2.0"]
+ * @usage
+ *
+ * @example
+ *
+ */
+ $classes = apply_filters( 'um_form_official_classes__hook', $classes );
return $classes;
}
@@ -165,7 +186,28 @@ if ( ! class_exists( 'Password' ) ) {
$args = array_merge( UM()->shortcodes()->get_css_args( $args ), $args );
}
- $args = apply_filters('um_reset_password_shortcode_args_filter', $args);
+ /**
+ * UM hook
+ *
+ * @type filter
+ * @title um_reset_password_shortcode_args_filter
+ * @description Extend Reset Password Arguments
+ * @input_vars
+ * [{"var":"$args","type":"array","desc":"Shortcode arguments"}]
+ * @change_log
+ * ["Since: 2.0"]
+ * @usage
+ *
+ * @example
+ *
+ */
+ $args = apply_filters( 'um_reset_password_shortcode_args_filter', $args );
if ( isset( $this->change_password ) ) {
diff --git a/includes/core/class-permalinks.php b/includes/core/class-permalinks.php
index 08393568..67ff23c0 100644
--- a/includes/core/class-permalinks.php
+++ b/includes/core/class-permalinks.php
@@ -42,7 +42,28 @@ if ( ! class_exists( 'Permalinks' ) ) {
if ( !is_singular() )
return;
- $enable_canonical = apply_filters("um_allow_canonical__filter", true );
+ /**
+ * UM hook
+ *
+ * @type filter
+ * @title um_allow_canonical__filter
+ * @description Allow canonical
+ * @input_vars
+ * [{"var":"$allow_canonical","type":"bool","desc":"Allow?"}]
+ * @change_log
+ * ["Since: 2.0"]
+ * @usage
+ *
+ * @example
+ *
+ */
+ $enable_canonical = apply_filters( "um_allow_canonical__filter", true );
if( ! $enable_canonical )
return;
@@ -160,6 +181,27 @@ if ( ! class_exists( 'Permalinks' ) ) {
$page_url = strtok( $page_url, '?' );
}
+ /**
+ * UM hook
+ *
+ * @type filter
+ * @title um_get_current_page_url
+ * @description Change current page URL
+ * @input_vars
+ * [{"var":"$page_url","type":"string","desc":"Page URL"}]
+ * @change_log
+ * ["Since: 2.0"]
+ * @usage
+ *
+ * @example
+ *
+ */
return apply_filters( 'um_get_current_page_url', $page_url );
}
@@ -209,9 +251,33 @@ if ( ! class_exists( 'Permalinks' ) ) {
/***
*** @makes an activate link for any user
***/
- function activate_url(){
- if ( !um_user('account_secret_hash') ) return false;
- $url = apply_filters( 'um_activate_url', home_url() );
+ function activate_url() {
+ if ( !um_user('account_secret_hash') ) {
+ return false;
+ }
+
+ /**
+ * UM hook
+ *
+ * @type filter
+ * @title um_activate_url
+ * @description Change activate user URL
+ * @input_vars
+ * [{"var":"$url","type":"string","desc":"Activate URL"}]
+ * @change_log
+ * ["Since: 2.0"]
+ * @usage
+ *
+ * @example
+ *
+ */
+ $url = apply_filters( 'um_activate_url', home_url() );
$url = add_query_arg( 'act', 'activate_via_email', $url );
$url = add_query_arg( 'hash', um_user('account_secret_hash'), $url );
$url = add_query_arg( 'user_id', um_user('ID'), $url );
@@ -282,6 +348,28 @@ if ( ! class_exists( 'Permalinks' ) ) {
$page_id = UM()->config()->permalinks['user'];
$profile_url = get_permalink( $page_id );
+ /**
+ * UM hook
+ *
+ * @type filter
+ * @title um_localize_permalink_filter
+ * @description Change user profile URL
+ * @input_vars
+ * [{"var":"$profile_url","type":"string","desc":"Profile URL"},
+ * {"var":"$page_id","type":"int","desc":"Profile Page ID"}]
+ * @change_log
+ * ["Since: 2.0"]
+ * @usage
+ *
+ * @example
+ *
+ */
$profile_url = apply_filters( 'um_localize_permalink_filter', $profile_url, $page_id );
if ( get_option('permalink_structure') ) {
diff --git a/includes/core/class-profile.php b/includes/core/class-profile.php
index 19bc2103..ceafca58 100644
--- a/includes/core/class-profile.php
+++ b/includes/core/class-profile.php
@@ -45,6 +45,27 @@ if ( ! class_exists( 'Profile' ) ) {
***/
function tabs() {
+ /**
+ * UM hook
+ *
+ * @type filter
+ * @title um_profile_tabs
+ * @description Extend user profile tabs
+ * @input_vars
+ * [{"var":"$tabs","type":"array","desc":"Profile tabs"}]
+ * @change_log
+ * ["Since: 2.0"]
+ * @usage
+ *
+ * @example
+ *
+ */
$tabs = apply_filters( 'um_profile_tabs', array(
'main' => array(
'name' => __( 'About', 'ultimate-member' ),
@@ -178,6 +199,27 @@ if ( ! class_exists( 'Profile' ) ) {
$this->active_tab = get_query_var('profiletab');
}
+ /**
+ * UM hook
+ *
+ * @type filter
+ * @title um_profile_active_tab
+ * @description Change active profile tab
+ * @input_vars
+ * [{"var":"$tab","type":"string","desc":"Active Profile tab"}]
+ * @change_log
+ * ["Since: 2.0"]
+ * @usage
+ *
+ * @example
+ *
+ */
$this->active_tab = apply_filters( 'um_profile_active_tab', $this->active_tab );
return $this->active_tab;
diff --git a/includes/core/class-query.php b/includes/core/class-query.php
index 04b5e7e2..06bff679 100644
--- a/includes/core/class-query.php
+++ b/includes/core/class-query.php
@@ -102,6 +102,27 @@ if ( ! class_exists( 'Query' ) ) {
unset( $args['post_type'] );
+ /**
+ * UM hook
+ *
+ * @type filter
+ * @title um_excluded_comment_types
+ * @description Extend excluded comment types
+ * @input_vars
+ * [{"var":"$types","type":"array","desc":"Comment Types"}]
+ * @change_log
+ * ["Since: 2.0"]
+ * @usage
+ *
+ * @example
+ *
+ */
$args['type__not_in'] = apply_filters( 'um_excluded_comment_types', array('') );
$comments = get_comments($args);
diff --git a/includes/core/class-register.php b/includes/core/class-register.php
index d022c8b2..2f38492e 100644
--- a/includes/core/class-register.php
+++ b/includes/core/class-register.php
@@ -18,7 +18,28 @@ if ( ! class_exists( 'Register' ) ) {
}
public function verify_nonce( $args ){
- $allow_nonce_verification = apply_filters("um_register_allow_nonce_verification", true );
+ /**
+ * UM hook
+ *
+ * @type filter
+ * @title um_register_allow_nonce_verification
+ * @description Enable/DIsable nonce verification of registration
+ * @input_vars
+ * [{"var":"$allow_nonce","type":"bool","desc":"Enable nonce"}]
+ * @change_log
+ * ["Since: 2.0"]
+ * @usage
+ *
+ * @example
+ *
+ */
+ $allow_nonce_verification = apply_filters( "um_register_allow_nonce_verification", true );
if( ! $allow_nonce_verification ){
return $args;
diff --git a/includes/core/class-rest-api.php b/includes/core/class-rest-api.php
index e04b68fa..f129fde3 100644
--- a/includes/core/class-rest-api.php
+++ b/includes/core/class-rest-api.php
@@ -31,9 +31,28 @@ if ( ! class_exists( 'REST_API' ) ) {
// Determine if JSON_PRETTY_PRINT is available
$this->pretty_print = defined( 'JSON_PRETTY_PRINT' ) ? JSON_PRETTY_PRINT : null;
- // Allow API request logging to be turned off
+ /**
+ * UM hook
+ *
+ * @type filter
+ * @title um_api_log_requests
+ * @description Allow API request logging to be turned off
+ * @input_vars
+ * [{"var":"$allow_log","type":"bool","desc":"Enable api logs"}]
+ * @change_log
+ * ["Since: 2.0"]
+ * @usage
+ *
+ * @example
+ *
+ */
$this->log_requests = apply_filters( 'um_api_log_requests', $this->log_requests );
-
}
/**
@@ -184,6 +203,7 @@ if ( ! class_exists( 'REST_API' ) ) {
}
// Determine the kind of query
+ $args = array();
$query_mode = $this->get_query_mode();
foreach( $this->vars as $k ) {
$args[ $k ] = isset( $wp_query->query_vars[ $k ] ) ? $wp_query->query_vars[ $k ] : null;
@@ -214,12 +234,55 @@ if ( ! class_exists( 'REST_API' ) ) {
break;
default:
- $data = apply_filters( 'um_rest_query_mode', $data , $query_mode, $args );
+ /**
+ * UM hook
+ *
+ * @type filter
+ * @title um_rest_query_mode
+ * @description Change query attributes
+ * @input_vars
+ * [{"var":"$data","type":"array","desc":"Query Data"},
+ * {"var":"$query_mode","type":"string","desc":"Query Mode"},
+ * {"var":"$args","type":"array","desc":"Query Arguments"}]
+ * @change_log
+ * ["Since: 2.0"]
+ * @usage
+ *
+ * @example
+ *
+ */
+ $data = apply_filters( 'um_rest_query_mode', $data, $query_mode, $args );
}
-
-
- // Allow extensions to setup their own return data
+ /**
+ * UM hook
+ *
+ * @type filter
+ * @title um_api_output_data
+ * @description Change output data for Rest API call
+ * @input_vars
+ * [{"var":"$data","type":"array","desc":"Output Data"},
+ * {"var":"$query_mode","type":"string","desc":"Query Mode"},
+ * {"var":"$api_class","type":"REST_API","desc":"REST_API instance"}]
+ * @change_log
+ * ["Since: 2.0"]
+ * @usage
+ *
+ * @example
+ *
+ */
$this->data = apply_filters( 'um_api_output_data', $data, $query_mode, $this );
// Log this API request, if enabled. We log it here because we have access to errors.
@@ -245,8 +308,28 @@ if ( ! class_exists( 'REST_API' ) ) {
$pending = UM()->user()->get_pending_users_count();
$response['stats']['pending_users'] = absint( $pending );
+ /**
+ * UM hook
+ *
+ * @type filter
+ * @title um_rest_api_get_stats
+ * @description Change output data for Rest API get stats call
+ * @input_vars
+ * [{"var":"$response","type":"array","desc":"Output Data"}]
+ * @change_log
+ * ["Since: 2.0"]
+ * @usage
+ *
+ * @example
+ *
+ */
$response = apply_filters( 'um_rest_api_get_stats', $response );
-
return $response;
}
@@ -347,6 +430,29 @@ if ( ! class_exists( 'REST_API' ) ) {
$val->profile_pic_normal = $this->getsrc( um_user('profile_photo', 200) );
$val->profile_pic_small = $this->getsrc( um_user('profile_photo', 40) );
$val->cover_photo = $this->getsrc( um_user('cover_photo', 1000) );
+
+ /**
+ * UM hook
+ *
+ * @type filter
+ * @title um_rest_userdata
+ * @description Change output data for Rest API userdata call
+ * @input_vars
+ * [{"var":"$value","type":"array","desc":"Output Data"},
+ * {"var":"$user_id","type":"string","desc":"User ID"}]
+ * @change_log
+ * ["Since: 2.0"]
+ * @usage
+ *
+ * @example
+ *
+ */
$val = apply_filters( 'um_rest_userdata', $val, $user->ID );
}
$response[ $user->ID ] = $val;
@@ -420,10 +526,32 @@ if ( ! class_exists( 'REST_API' ) ) {
switch( $field ) {
default:
- $response[$field] = ( um_profile( $field ) ) ? um_profile( $field ) : '';
+ $response[ $field ] = ( um_profile( $field ) ) ? um_profile( $field ) : '';
+ /**
+ * UM hook
+ *
+ * @type filter
+ * @title um_rest_get_auser
+ * @description Change output data for Rest API user authentification call
+ * @input_vars
+ * [{"var":"$response","type":"array","desc":"Output Data"},
+ * {"var":"$field","type":"string","desc":"Field Key"},
+ * {"var":"$user_id","type":"int","desc":"User ID"}]
+ * @change_log
+ * ["Since: 2.0"]
+ * @usage
+ *
+ * @example
+ *
+ */
$response = apply_filters( 'um_rest_get_auser', $response, $field, $user->ID );
-
break;
case 'cover_photo':
@@ -467,6 +595,29 @@ if ( ! class_exists( 'REST_API' ) ) {
$val->profile_pic_normal = $this->getsrc( um_user('profile_photo', 200) );
$val->profile_pic_small = $this->getsrc( um_user('profile_photo', 40) );
$val->cover_photo = $this->getsrc( um_user('cover_photo', 1000) );
+
+ /**
+ * UM hook
+ *
+ * @type filter
+ * @title um_rest_userdata
+ * @description Change output data for Rest API userdata call
+ * @input_vars
+ * [{"var":"$value","type":"array","desc":"Output Data"},
+ * {"var":"$user_id","type":"string","desc":"User ID"}]
+ * @change_log
+ * ["Since: 2.0"]
+ * @usage
+ *
+ * @example
+ *
+ */
$val = apply_filters( 'um_rest_userdata', $val, $user->ID );
}
$response = $val;
@@ -493,7 +644,27 @@ if ( ! class_exists( 'REST_API' ) ) {
public function get_query_mode() {
global $wp_query;
- // Whitelist our query options
+ /**
+ * UM hook
+ *
+ * @type filter
+ * @title um_api_valid_query_modes
+ * @description Whitelist UM query options
+ * @input_vars
+ * [{"var":"$list","type":"array","desc":"Whitelist"}]
+ * @change_log
+ * ["Since: 2.0"]
+ * @usage
+ *
+ * @example
+ *
+ */
$accepted = apply_filters( 'um_api_valid_query_modes', array(
'get.users',
'get.user',
@@ -534,6 +705,27 @@ if ( ! class_exists( 'REST_API' ) ) {
$format = isset( $wp_query->query_vars['format'] ) ? $wp_query->query_vars['format'] : 'json';
+ /**
+ * UM hook
+ *
+ * @type filter
+ * @title um_api_output_format
+ * @description UM Rest API output format
+ * @input_vars
+ * [{"var":"$format","type":"string","desc":"Format"}]
+ * @change_log
+ * ["Since: 2.0"]
+ * @usage
+ *
+ * @example
+ *
+ */
return apply_filters( 'um_api_output_format', $format );
}
diff --git a/includes/core/class-rewrite.php b/includes/core/class-rewrite.php
index 1964d8ea..b00e7e5b 100644
--- a/includes/core/class-rewrite.php
+++ b/includes/core/class-rewrite.php
@@ -108,7 +108,28 @@ if ( ! class_exists( 'Rewrite' ) ) {
'top'
);
- if( ! apply_filters( 'um_rewrite_flush_rewrite_rules', UM()->options()->get( 'um_flush_stop' ) ) )
+ /**
+ * UM hook
+ *
+ * @type filter
+ * @title um_rewrite_flush_rewrite_rules
+ * @description Enable flushing rewrite rules
+ * @input_vars
+ * [{"var":"$stop_flush","type":"bool","desc":"Stop flushing rewrite rules"}]
+ * @change_log
+ * ["Since: 2.0"]
+ * @usage
+ *
+ * @example
+ *
+ */
+ if ( ! apply_filters( 'um_rewrite_flush_rewrite_rules', UM()->options()->get( 'um_flush_stop' ) ) )
flush_rewrite_rules( true );
}
@@ -200,6 +221,27 @@ if ( ! class_exists( 'Rewrite' ) ) {
exit( wp_redirect( $url ) );
} else {
+ /**
+ * UM hook
+ *
+ * @type filter
+ * @title um_locate_user_profile_not_loggedin__redirect
+ * @description Change redirect URL from user profile for not logged in user
+ * @input_vars
+ * [{"var":"$url","type":"string","desc":"Redirect URL"}]
+ * @change_log
+ * ["Since: 2.0"]
+ * @usage
+ *
+ * @example
+ *
+ */
$redirect_to = apply_filters( 'um_locate_user_profile_not_loggedin__redirect', home_url() );
if ( ! empty( $redirect_to ) ){
exit( wp_redirect( $redirect_to ) );
diff --git a/includes/core/class-roles-capabilities.php b/includes/core/class-roles-capabilities.php
index 0d8e2613..ef79b02c 100644
--- a/includes/core/class-roles-capabilities.php
+++ b/includes/core/class-roles-capabilities.php
@@ -137,6 +137,29 @@ if ( ! class_exists( 'Roles_Capabilities' ) ) {
$new_role = false;
}
+ /**
+ * UM hook
+ *
+ * @type filter
+ * @title um_set_user_role
+ * @description User role was changed
+ * @input_vars
+ * [{"var":"$new_role","type":"string","desc":"New role"},
+ * {"var":"$user_id","type":"int","desc":"User ID"},
+ * {"var":"$user","type":"array","desc":"Userdata"}]
+ * @change_log
+ * ["Since: 2.0"]
+ * @usage
+ *
+ * @example
+ *
+ */
return apply_filters( 'um_set_user_role', $new_role, $user_id, $user );
}
@@ -472,6 +495,29 @@ if ( ! class_exists( 'Roles_Capabilities' ) ) {
$user_id = get_current_user_id();
$role = UM()->roles()->get_priority_user_role( $user_id );
$permissions = $this->role_data( $role );
+
+ /**
+ * UM hook
+ *
+ * @type filter
+ * @title um_user_permissions_filter
+ * @description Change User Permissions
+ * @input_vars
+ * [{"var":"$permissions","type":"array","desc":"User Permissions"},
+ * {"var":"$user_id","type":"int","desc":"User ID"}]
+ * @change_log
+ * ["Since: 2.0"]
+ * @usage
+ *
+ * @example
+ *
+ */
$permissions = apply_filters( 'um_user_permissions_filter', $permissions, $user_id );
if ( isset( $permissions[ $permission ] ) && is_serialized( $permissions[ $permission ] ) )
diff --git a/includes/core/class-setup.php b/includes/core/class-setup.php
index a923c143..aca5c421 100644
--- a/includes/core/class-setup.php
+++ b/includes/core/class-setup.php
@@ -188,8 +188,8 @@ if ( ! class_exists( 'Setup' ) ) {
}
foreach ( $core_pages as $slug => $page_id ) {
- $key = apply_filters( 'um_core_page_id_filter', 'core_' . $slug );
- $options[$key] = $page_id;
+ $key = UM()->options()->get_core_page_id( $slug );
+ $options[ $key ] = $page_id;
}
}
diff --git a/includes/core/class-shortcodes.php b/includes/core/class-shortcodes.php
index 7614caca..f26ad3f6 100644
--- a/includes/core/class-shortcodes.php
+++ b/includes/core/class-shortcodes.php
@@ -27,6 +27,27 @@ if ( ! class_exists( 'Shortcodes' ) ) {
add_filter( 'um_shortcode_args_filter', array( &$this, 'display_logout_form' ), 99 );
add_filter( 'um_shortcode_args_filter', array( &$this, 'parse_shortcode_args' ), 99 );
+ /**
+ * UM hook
+ *
+ * @type filter
+ * @title um_emoji_base_uri
+ * @description Change Emoji base URL
+ * @input_vars
+ * [{"var":"$url","type":"string","desc":"Base URL"}]
+ * @change_log
+ * ["Since: 2.0"]
+ * @usage
+ *
+ * @example
+ *
+ */
$base_uri = apply_filters( 'um_emoji_base_uri', 'https://s.w.org/images/core/emoji/' );
$this->emoji[':)'] = $base_uri . '72x72/1f604.png';
@@ -256,7 +277,28 @@ if ( ! class_exists( 'Shortcodes' ) ) {
$classes .= ' um-' . $args['template'];
}
- $classes = apply_filters('um_form_official_classes__hook', $classes);
+ /**
+ * UM hook
+ *
+ * @type filter
+ * @title um_form_official_classes__hook
+ * @description Change official form classes
+ * @input_vars
+ * [{"var":"$classes","type":"string","desc":"Classes string"}]
+ * @change_log
+ * ["Since: 2.0"]
+ * @usage
+ *
+ * @example
+ *
+ */
+ $classes = apply_filters( 'um_form_official_classes__hook', $classes );
return $classes;
}
@@ -343,7 +385,28 @@ if ( ! class_exists( 'Shortcodes' ) ) {
// get data into one global array
$post_data = UM()->query()->post_data($this->form_id);
- $args = apply_filters('um_pre_args_setup', $post_data);
+ /**
+ * UM hook
+ *
+ * @type filter
+ * @title um_pre_args_setup
+ * @description Change arguments on load shortcode
+ * @input_vars
+ * [{"var":"$post_data","type":"string","desc":"$_POST data"}]
+ * @change_log
+ * ["Since: 2.0"]
+ * @usage
+ *
+ * @example
+ *
+ */
+ $args = apply_filters( 'um_pre_args_setup', $post_data );
if (!isset($args['template'])) {
$args['template'] = '';
@@ -372,7 +435,29 @@ if ( ! class_exists( 'Shortcodes' ) ) {
}
}
// filter for arguments
- $args = apply_filters('um_shortcode_args_filter', $args);
+
+ /**
+ * UM hook
+ *
+ * @type filter
+ * @title um_shortcode_args_filter
+ * @description Change arguments on load shortcode
+ * @input_vars
+ * [{"var":"$args","type":"string","desc":"Shortcode arguments"}]
+ * @change_log
+ * ["Since: 2.0"]
+ * @usage
+ *
+ * @example
+ *
+ */
+ $args = apply_filters( 'um_shortcode_args_filter', $args );
extract($args, EXTR_SKIP);
@@ -432,8 +517,26 @@ if ( ! class_exists( 'Shortcodes' ) ) {
* @return string
*/
function dynamic_css( $args = array() ) {
- /*
- * for fix the issue #306
+ /**
+ * UM hook
+ *
+ * @type filter
+ * @title um_disable_dynamic_global_css
+ * @description Turn on for disable global dynamic CSS for fix the issue #306
+ * @input_vars
+ * [{"var":"$disable","type":"bool","desc":"Disable global CSS"}]
+ * @change_log
+ * ["Since: 2.0"]
+ * @usage
+ *
+ * @example
+ *
*/
$disable_css = apply_filters( 'um_disable_dynamic_global_css', false );
if ( $disable_css )
@@ -594,6 +697,27 @@ if ( ! class_exists( 'Shortcodes' ) ) {
'{username}',
);
+ /**
+ * UM hook
+ *
+ * @type filter
+ * @title um_allowed_user_tags_patterns
+ * @description Extend user placeholders patterns
+ * @input_vars
+ * [{"var":"$patterns","type":"array","desc":"Placeholders"}]
+ * @change_log
+ * ["Since: 2.0"]
+ * @usage
+ *
+ * @example
+ *
+ */
$pattern_array = apply_filters( 'um_allowed_user_tags_patterns', $pattern_array );
//$matches = false;
@@ -616,6 +740,28 @@ if ( ! class_exists( 'Shortcodes' ) ) {
$value = um_user( 'user_login' );
}
+ /**
+ * UM hook
+ *
+ * @type filter
+ * @title um_profile_tag_hook__{$usermeta}
+ * @description Change usermeta field value
+ * @input_vars
+ * [{"var":"$value","type":"array","desc":"Meta field value"},
+ * {"var":"$user_id","type":"array","desc":"User ID"}]
+ * @change_log
+ * ["Since: 2.0"]
+ * @usage
+ *
+ * @example
+ *
+ */
$value = apply_filters( "um_profile_tag_hook__{$usermeta}", $value, um_user( 'ID' ) );
}
diff --git a/includes/core/class-user-posts.php b/includes/core/class-user-posts.php
index e5a4897a..9aef4c3c 100644
--- a/includes/core/class-user-posts.php
+++ b/includes/core/class-user-posts.php
@@ -4,105 +4,157 @@ namespace um\core;
// Exit if accessed directly
if ( ! defined( 'ABSPATH' ) ) exit;
-
if ( ! class_exists( 'User_posts' ) ) {
- class User_posts {
-
- function __construct() {
-
- add_action('um_profile_content_posts', array(&$this, 'add_posts') );
- add_action('um_profile_content_comments', array(&$this, 'add_comments') );
-
- add_action('um_ajax_load_posts__um_load_posts', array(&$this, 'load_posts') );
- add_action('um_ajax_load_posts__um_load_comments', array(&$this, 'load_comments') );
-
- }
-
- /***
- *** @dynamic load of posts
- ***/
- function load_posts( $args ) {
- $array = explode(',', $args );
- $post_type = $array[0];
- $posts_per_page = $array[1];
- $offset = $array[2];
- $author = $array[3];
-
- $offset_n = $posts_per_page + $offset;
-
- UM()->shortcodes()->modified_args = "$post_type,$posts_per_page,$offset_n,$author";
-
- UM()->shortcodes()->loop = UM()->query()->make("post_type=$post_type&posts_per_page=$posts_per_page&offset=$offset&author=$author");
-
- UM()->shortcodes()->load_template('profile/posts-single');
-
- }
-
- /***
- *** @dynamic load of comments
- ***/
- function load_comments( $args ) {
- $array = explode(',', $args );
- $post_type = $array[0];
- $posts_per_page = $array[1];
- $offset = $array[2];
- $author = $array[3];
-
- $offset_n = $posts_per_page + $offset;
-
- UM()->shortcodes()->modified_args = "$post_type,$posts_per_page,$offset_n,$author";
-
- UM()->shortcodes()->loop = UM()->query()->make("post_type=$post_type&number=$posts_per_page&offset=$offset&user_id=$author");
-
- UM()->shortcodes()->load_template('profile/comments-single');
-
- }
- /***
- *** @add posts
- ***/
- function add_posts() {
- UM()->shortcodes()->load_template('profile/posts');
- }
+ /**
+ * Class User_posts
+ * @package um\core
+ */
+ class User_posts {
- /***
- *** @add comments
- ***/
- function add_comments() {
- UM()->shortcodes()->load_template('profile/comments');
- }
+ /**
+ * User_posts constructor.
+ */
+ function __construct() {
+ add_action( 'um_profile_content_posts', array( &$this, 'add_posts' ) );
+ add_action( 'um_profile_content_comments', array( &$this, 'add_comments' ) );
- /***
- *** @count posts
- ***/
- function count_user_posts_by_type( $user_id= '', $post_type = 'post' ) {
- global $wpdb;
- if ( !$user_id )
- $user_id = um_user('ID');
+ add_action( 'um_ajax_load_posts__um_load_posts', array( &$this, 'load_posts' ) );
+ add_action( 'um_ajax_load_posts__um_load_comments', array( &$this, 'load_comments' ) );
+ }
- if ( !$user_id ) return 0;
- $where = get_posts_by_author_sql( $post_type, true, $user_id );
- $count = $wpdb->get_var( "SELECT COUNT(*) FROM $wpdb->posts $where" );
+ /**
+ * Dynamic load of posts
+ *
+ * @param array $args
+ */
+ function load_posts( $args ) {
+ $array = explode(',', $args );
+ $post_type = $array[0];
+ $posts_per_page = $array[1];
+ $offset = $array[2];
+ $author = $array[3];
- return apply_filters('um_pretty_number_formatting', $count);
- }
+ $offset_n = $posts_per_page + $offset;
- /***
- *** @count comments
- ***/
- function count_user_comments( $user_id = null ) {
- global $wpdb;
- if ( !$user_id )
- $user_id = um_user('ID');
+ UM()->shortcodes()->modified_args = "$post_type,$posts_per_page,$offset_n,$author";
- if ( !$user_id ) return 0;
+ UM()->shortcodes()->loop = UM()->query()->make("post_type=$post_type&posts_per_page=$posts_per_page&offset=$offset&author=$author");
- $count = $wpdb->get_var("SELECT COUNT(comment_ID) FROM " . $wpdb->comments. " WHERE user_id = " . $user_id . " AND comment_approved = '1'");
+ UM()->shortcodes()->load_template('profile/posts-single');
+ }
- return apply_filters('um_pretty_number_formatting', $count);
- }
+ /**
+ * Dynamic load of comments
+ *
+ * @param $args
+ */
+ function load_comments( $args ) {
+ $array = explode(',', $args );
+ $post_type = $array[0];
+ $posts_per_page = $array[1];
+ $offset = $array[2];
+ $author = $array[3];
- }
+ $offset_n = $posts_per_page + $offset;
+
+ UM()->shortcodes()->modified_args = "$post_type,$posts_per_page,$offset_n,$author";
+
+ UM()->shortcodes()->loop = UM()->query()->make("post_type=$post_type&number=$posts_per_page&offset=$offset&user_id=$author");
+
+ UM()->shortcodes()->load_template('profile/comments-single');
+ }
+
+
+ /**
+ * Add posts
+ */
+ function add_posts() {
+ UM()->shortcodes()->load_template( 'profile/posts' );
+ }
+
+
+ /**
+ * Add comments
+ */
+ function add_comments() {
+ UM()->shortcodes()->load_template( 'profile/comments' );
+ }
+
+
+ /**
+ * Count posts by type
+ *
+ * @param string $user_id
+ * @param string $post_type
+ *
+ * @return int|string
+ */
+ function count_user_posts_by_type( $user_id= '', $post_type = 'post' ) {
+ global $wpdb;
+ if ( !$user_id )
+ $user_id = um_user( 'ID' );
+
+ if ( !$user_id ) return 0;
+
+ $where = get_posts_by_author_sql( $post_type, true, $user_id );
+ $count = $wpdb->get_var( "SELECT COUNT(*) FROM $wpdb->posts $where" );
+
+ return $this->pretty_number_formatting( $count );
+ }
+
+
+ /**
+ * Count comments
+ *
+ * @param int|null $user_id
+ *
+ * @return int|string
+ */
+ function count_user_comments( $user_id = null ) {
+ global $wpdb;
+ if ( !$user_id )
+ $user_id = um_user('ID');
+
+ if ( !$user_id ) return 0;
+
+ $count = $wpdb->get_var("SELECT COUNT(comment_ID) FROM " . $wpdb->comments. " WHERE user_id = " . $user_id . " AND comment_approved = '1'");
+
+ return $this->pretty_number_formatting( $count );
+ }
+
+
+ /**
+ * @param int $count
+ *
+ * @return string
+ */
+ function pretty_number_formatting( $count ) {
+ /**
+ * UM hook
+ *
+ * @type filter
+ * @title um_pretty_number_formatting
+ * @description Change User Posts count value
+ * @input_vars
+ * [{"var":"$count","type":"int","desc":"Posts Count"}]
+ * @change_log
+ * ["Since: 2.0"]
+ * @usage
+ *
+ * @example
+ *
+ */
+ return apply_filters( 'um_pretty_number_formatting', $count );
+ }
+
+ }
}
\ No newline at end of file
diff --git a/includes/core/class-user.php b/includes/core/class-user.php
index 00b695be..dd23a0c9 100644
--- a/includes/core/class-user.php
+++ b/includes/core/class-user.php
@@ -155,6 +155,28 @@ if ( ! class_exists( 'User' ) ) {
'value' => 'awaiting_admin_review',
'compare' => '='
);
+
+ /**
+ * UM hook
+ *
+ * @type filter
+ * @title um_admin_pending_queue_filter
+ * @description Change user query arguments when get pending users
+ * @input_vars
+ * [{"var":"$args","type":"array","desc":"WP_Users query arguments"}]
+ * @change_log
+ * ["Since: 2.0"]
+ * @usage
+ *
+ * @example
+ *
+ */
$args = apply_filters( 'um_admin_pending_queue_filter', $args );
$users = new \WP_User_Query( $args );
@@ -371,6 +393,28 @@ if ( ! class_exists( 'User' ) ) {
*/
function profile_form_additional_section( $userdata ) {
+ /**
+ * UM hook
+ *
+ * @type filter
+ * @title um_user_profile_additional_fields
+ * @description Make additional content section
+ * @input_vars
+ * [{"var":"$content","type":"array","desc":"Additional section content"},
+ * {"var":"$userdata","type":"array","desc":"Userdata"}]
+ * @change_log
+ * ["Since: 2.0"]
+ * @usage
+ *
+ * @example
+ *
+ */
$section_content = apply_filters( 'um_user_profile_additional_fields', '', $userdata );
if ( ! empty( $section_content ) && ! ( is_multisite() && is_network_admin() ) ) {
@@ -489,7 +533,29 @@ if ( ! class_exists( 'User' ) ) {
if ( is_numeric( $user_id ) && $user_id > 0 ) {
$find_user = get_option("um_cache_userdata_{$user_id}");
if ( $find_user ) {
- $find_user = apply_filters('um_user_permissions_filter', $find_user, $user_id);
+ /**
+ * UM hook
+ *
+ * @type filter
+ * @title um_user_permissions_filter
+ * @description Change User Permissions
+ * @input_vars
+ * [{"var":"$permissions","type":"array","desc":"User Permissions"},
+ * {"var":"$user_id","type":"int","desc":"User ID"}]
+ * @change_log
+ * ["Since: 2.0"]
+ * @usage
+ *
+ * @example
+ *
+ */
+ $find_user = apply_filters( 'um_user_permissions_filter', $find_user, $user_id );
return $find_user;
}
}
@@ -627,6 +693,28 @@ if ( ! class_exists( 'User' ) ) {
$this->profile['roles'] = UM()->roles()->get_all_user_roles( $this->id );
$role_meta = UM()->roles()->role_data( $user_role );
+ /**
+ * UM hook
+ *
+ * @type filter
+ * @title um_user_permissions_filter
+ * @description Change User Permissions
+ * @input_vars
+ * [{"var":"$permissions","type":"array","desc":"User Permissions"},
+ * {"var":"$user_id","type":"int","desc":"User ID"}]
+ * @change_log
+ * ["Since: 2.0"]
+ * @usage
+ *
+ * @example
+ *
+ */
$role_meta = apply_filters( 'um_user_permissions_filter', $role_meta, $this->id );
/*$role_meta = array_map( function( $key, $item ) {
@@ -725,7 +813,28 @@ if ( ! class_exists( 'User' ) ) {
unset( $submitted['confirm_user_password'] );
}
- $submitted = apply_filters('um_before_save_filter_submitted', $submitted );
+ /**
+ * UM hook
+ *
+ * @type filter
+ * @title um_before_save_filter_submitted
+ * @description Change submitted data before save usermeta "submitted" on registration process
+ * @input_vars
+ * [{"var":"$submitted","type":"array","desc":"Submitted data"}]
+ * @change_log
+ * ["Since: 2.0"]
+ * @usage
+ *
+ * @example
+ *
+ */
+ $submitted = apply_filters( 'um_before_save_filter_submitted', $submitted );
do_action('um_before_save_registration_details', $this->id, $submitted );
@@ -1059,6 +1168,27 @@ if ( ! class_exists( 'User' ) ) {
function get_admin_actions() {
$items = array();
$actions = array();
+ /**
+ * UM hook
+ *
+ * @type filter
+ * @title um_admin_user_actions_hook
+ * @description Extend admin actions for each user
+ * @input_vars
+ * [{"var":"$actions","type":"array","desc":"Actions for user"}]
+ * @change_log
+ * ["Since: 2.0"]
+ * @usage
+ *
+ * @example
+ *
+ */
$actions = apply_filters('um_admin_user_actions_hook', $actions );
if ( !isset( $actions ) || empty( $actions ) ) return false;
foreach($actions as $id => $arr ) {
@@ -1144,7 +1274,30 @@ if ( ! class_exists( 'User' ) ) {
$privacy = get_user_meta( $user_id, 'profile_privacy', true );
if ( $privacy == $case ) {
- $bool = apply_filters('um_is_private_filter_hook', false, $privacy, $user_id );
+ /**
+ * UM hook
+ *
+ * @type filter
+ * @title um_is_private_filter_hook
+ * @description Change user privacy
+ * @input_vars
+ * [{"var":"$is_private","type":"bool","desc":"Is user private"},
+ * {"var":"$privacy","type":"bool","desc":"Profile Privacy"},
+ * {"var":"$user_id","type":"int","desc":"User ID"}]
+ * @change_log
+ * ["Since: 2.0"]
+ * @usage
+ *
+ * @example
+ *
+ */
+ $bool = apply_filters( 'um_is_private_filter_hook', false, $privacy, $user_id );
return $bool;
}
@@ -1170,7 +1323,30 @@ if ( ! class_exists( 'User' ) ) {
function update_profile( $changes ) {
$args['ID'] = $this->id;
- $changes = apply_filters('um_before_update_profile', $changes, $this->id);
+
+ /**
+ * UM hook
+ *
+ * @type filter
+ * @title um_before_update_profile
+ * @description Change update profile changes data
+ * @input_vars
+ * [{"var":"$changes","type":"array","desc":"User Profile Changes"},
+ * {"var":"$user_id","type":"int","desc":"User ID"}]
+ * @change_log
+ * ["Since: 2.0"]
+ * @usage
+ *
+ * @example
+ *
+ */
+ $changes = apply_filters('um_before_update_profile', $changes, $this->id );
// save or update profile meta
foreach ( $changes as $key => $value ) {
diff --git a/includes/core/class-validation.php b/includes/core/class-validation.php
index 646e2db5..8788d72f 100644
--- a/includes/core/class-validation.php
+++ b/includes/core/class-validation.php
@@ -5,183 +5,295 @@ namespace um\core;
if ( ! defined( 'ABSPATH' ) ) exit;
if ( ! class_exists( 'Validation' ) ) {
- class Validation {
- function __construct() {
- $this->regex_safe = '/\A[\w\-\.]+\z/';
- $this->regex_phone_number = '/\A[\d\-\.\+\(\)\ ]+\z/';
+ /**
+ * Class Validation
+ * @package um\core
+ */
+ class Validation {
- }
- /***
- *** @removes html from any string
- ***/
- function remove_html($string) {
- return wp_strip_all_tags( $string );
- }
+ /**
+ * Validation constructor.
+ */
+ function __construct() {
+ $this->regex_safe = '/\A[\w\-\.]+\z/';
+ $this->regex_phone_number = '/\A[\d\-\.\+\(\)\ ]+\z/';
+ }
- /***
- *** @normalize a string
- ***/
- function normalize($string) {
- $string = preg_replace('~&([a-z]{1,2})(acute|cedil|circ|grave|lig|orn|ring|slash|th|tilde|uml);~i', '$1', htmlentities($string, ENT_QUOTES, 'UTF-8'));
- return $string;
- }
- /***
- *** @safe name usage ( for url purposes )
- ***/
- function safe_name_in_url( $name ) {
- $name = strtolower( $name );
- $name = preg_replace("/'/","", $name );
- $name = stripslashes( $name );
- $name = $this->normalize($name);
- $name = rawurldecode( $name );
- return $name;
- }
+ /**
+ * Removes html from any string
+ *
+ * @param $string
+ *
+ * @return string
+ */
+ function remove_html( $string ) {
+ return wp_strip_all_tags( $string );
+ }
- /***
- *** @password test
- ***/
- function strong_pass($candidate) {
- $r1='/[A-Z]/';
- $r2='/[a-z]/';
- $r3='/[0-9]/';
- if(preg_match_all($r1,$candidate, $o)<1) return false;
- if(preg_match_all($r2,$candidate, $o)<1) return false;
- if(preg_match_all($r3,$candidate, $o)<1) return false;
- return true;
- }
- /***
- *** @space, dash, underscore
- ***/
- function safe_username( $string ) {
+ /**
+ * Normalize a string
+ *
+ * @param $string
+ *
+ * @return mixed
+ */
+ function normalize( $string ) {
+ $string = preg_replace('~&([a-z]{1,2})(acute|cedil|circ|grave|lig|orn|ring|slash|th|tilde|uml);~i', '$1', htmlentities($string, ENT_QUOTES, 'UTF-8'));
+ return $string;
+ }
- $regex_safe_username = apply_filters('um_validation_safe_username_regex',$this->regex_safe );
- if ( is_email( $string ) )
- return true;
- if ( !is_email( $string) && !preg_match( $regex_safe_username, $string ) )
- return false;
- return true;
- }
+ /**
+ * Safe name usage ( for url purposes )
+ *
+ * @param $name
+ *
+ * @return mixed|string
+ */
+ function safe_name_in_url( $name ) {
+ $name = strtolower( $name );
+ $name = preg_replace("/'/","", $name );
+ $name = stripslashes( $name );
+ $name = $this->normalize($name);
+ $name = rawurldecode( $name );
+ return $name;
+ }
- /***
- *** @dash and underscore (metakey)
- ***/
- function safe_string($string){
- $regex_safe_string = apply_filters('um_validation_safe_string_regex',$this->regex_safe );
+ /**
+ * Password test
+ *
+ * @param $candidate
+ *
+ * @return bool
+ */
+ function strong_pass( $candidate ) {
+ $r1='/[A-Z]/';
+ $r2='/[a-z]/';
+ $r3='/[0-9]/';
+ if(preg_match_all($r1,$candidate, $o)<1) return false;
+ if(preg_match_all($r2,$candidate, $o)<1) return false;
+ if(preg_match_all($r3,$candidate, $o)<1) return false;
+ return true;
+ }
- if ( !preg_match( $regex_safe_string, $string) ){
- return false;
- }
- return true;
- }
- /***
- *** @is phone number
- ***/
- function is_phone_number( $string ){
- if ( !$string )
- return true;
- if ( !preg_match( $this->regex_phone_number, $string) )
- return false;
- return true;
- }
+ /**
+ * Space, dash, underscore
+ *
+ * @param $string
+ *
+ * @return bool
+ */
+ function safe_username( $string ) {
- /***
- *** @is url
- ***/
- function is_url( $url, $social = false ){
- if ( !$url ) return true;
+ /**
+ * UM hook
+ *
+ * @type filter
+ * @title um_validation_safe_username_regex
+ * @description Change validation regex for username
+ * @input_vars
+ * [{"var":"$regex_safe","type":"string","desc":"Regex"}]
+ * @change_log
+ * ["Since: 2.0"]
+ * @usage
+ *
+ * @example
+ *
+ */
+ $regex_safe_username = apply_filters('um_validation_safe_username_regex',$this->regex_safe );
- if ( $social ) {
+ if ( is_email( $string ) )
+ return true;
+ if ( !is_email( $string) && !preg_match( $regex_safe_username, $string ) )
+ return false;
+ return true;
+ }
- if ( !filter_var($url, FILTER_VALIDATE_URL) && strstr( $url, $social ) ) { // starts with social requested
- return true;
- } else {
- if ( filter_var($url, FILTER_VALIDATE_URL) && strstr( $url, $social ) ) {
- return true;
- } elseif ( preg_match( $this->regex_safe, $url) ) {
+ /**
+ * Dash and underscore (metakey)
+ *
+ * @param $string
+ *
+ * @return bool
+ */
+ function safe_string( $string ) {
- if ( strstr( $url, '.com' ) ){
- return false;
- } else {
- return true;
- }
+ /**
+ * UM hook
+ *
+ * @type filter
+ * @title um_validation_safe_string_regex
+ * @description Change validation regex for each string
+ * @input_vars
+ * [{"var":"$regex_safe","type":"string","desc":"Regex"}]
+ * @change_log
+ * ["Since: 2.0"]
+ * @usage
+ *
+ * @example
+ *
+ */
+ $regex_safe_string = apply_filters('um_validation_safe_string_regex',$this->regex_safe );
- }
+ if ( !preg_match( $regex_safe_string, $string) ){
+ return false;
+ }
+ return true;
+ }
- }
- } else {
+ /**
+ * Ss phone number
+ *
+ * @param $string
+ *
+ * @return bool
+ */
+ function is_phone_number( $string ) {
+ if ( !$string )
+ return true;
+ if ( !preg_match( $this->regex_phone_number, $string) )
+ return false;
+ return true;
+ }
- if ( strstr( $url, 'http://') || strstr( $url, 'https://') )
- return true;
- }
+ /**
+ * Is url
+ *
+ * @param $url
+ * @param bool $social
+ *
+ * @return bool
+ */
+ function is_url( $url, $social = false ){
+ if ( !$url ) return true;
- return false;
- }
+ if ( $social ) {
- /***
- *** @get a random string
- ***/
- function randomize( $length = 10 ) {
- $characters = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
- $result = '';
- for ($i = 0; $i < $length; $i++) {
- $result .= $characters[rand(0, strlen($characters) - 1)];
- }
- return $result;
- }
+ if ( !filter_var($url, FILTER_VALIDATE_URL) && strstr( $url, $social ) ) { // starts with social requested
+ return true;
+ } else {
- /***
- *** @generate a password, hash, or similar
- ***/
- function generate( $length = 40 ) {
- return wp_generate_password( $length, false );
- }
+ if ( filter_var($url, FILTER_VALIDATE_URL) && strstr( $url, $social ) ) {
+ return true;
+ } elseif ( preg_match( $this->regex_safe, $url) ) {
- /***
- *** @random numbers only
- ***/
- function random_number($len = false) {
- $ints = array();
- $len = $len ? $len : rand(2,9);
- if($len > 9)
- {
- trigger_error('Maximum length should not exceed 9');
- return 0;
- }
- while(true)
- {
- $current = rand(0,9);
- if(!in_array($current,$ints))
- {
- $ints[] = $current;
- }
- if(count($ints) == $len)
- {
- return implode($ints);
- }
- }
- }
+ if ( strstr( $url, '.com' ) ){
+ return false;
+ } else {
+ return true;
+ }
- /***
- *** @To validate given date input
- ***/
- function validate_date( $date, $format='YYYY/MM/D' ) {
- if ( strlen( $date ) < strlen($format) ) return false;
- if ( $date[4] != '/' ) return false;
- if ( $date[7] != '/' ) return false;
- if ( false === strtotime($date) ) return false;
- return true;
- }
+ }
- }
+ }
+
+ } else {
+
+ if ( strstr( $url, 'http://') || strstr( $url, 'https://') )
+ return true;
+
+ }
+
+ return false;
+ }
+
+
+ /**
+ * Get a random string
+ *
+ * @param int $length
+ *
+ * @return string
+ */
+ function randomize( $length = 10 ) {
+ $characters = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
+ $result = '';
+ for ($i = 0; $i < $length; $i++) {
+ $result .= $characters[rand(0, strlen($characters) - 1)];
+ }
+ return $result;
+ }
+
+
+ /**
+ * Generate a password, hash, or similar
+ *
+ * @param int $length
+ *
+ * @return string
+ */
+ function generate( $length = 40 ) {
+ return wp_generate_password( $length, false );
+ }
+
+
+ /**
+ * Random numbers only
+ *
+ * @param bool $len
+ *
+ * @return int|string
+ */
+ function random_number( $len = false ) {
+ $ints = array();
+ $len = $len ? $len : rand(2,9);
+ if($len > 9)
+ {
+ trigger_error('Maximum length should not exceed 9');
+ return 0;
+ }
+ while(true)
+ {
+ $current = rand(0,9);
+ if(!in_array($current,$ints))
+ {
+ $ints[] = $current;
+ }
+ if(count($ints) == $len)
+ {
+ return implode($ints);
+ }
+ }
+ }
+
+
+ /**
+ * To validate given date input
+ *
+ * @param $date
+ * @param string $format
+ *
+ * @return bool
+ */
+ function validate_date( $date, $format='YYYY/MM/D' ) {
+ if ( strlen( $date ) < strlen($format) ) return false;
+ if ( $date[4] != '/' ) return false;
+ if ( $date[7] != '/' ) return false;
+ if ( false === strtotime($date) ) return false;
+ return true;
+ }
+
+ }
}
\ No newline at end of file
diff --git a/includes/core/um-actions-account.php b/includes/core/um-actions-account.php
index ef977e73..2d6d580d 100644
--- a/includes/core/um-actions-account.php
+++ b/includes/core/um-actions-account.php
@@ -160,7 +160,30 @@ function um_submit_account_errors_hook( $args ) {
$arr_fields = array();
$account_fields = get_user_meta( um_user('ID'), 'um_account_secure_fields', true );
- $secure_fields = apply_filters( 'um_secure_account_fields', $account_fields , um_user( 'ID' ) );
+
+ /**
+ * UM hook
+ *
+ * @type filter
+ * @title um_secure_account_fields
+ * @description Change secure account fields
+ * @input_vars
+ * [{"var":"$fields","type":"array","desc":"Secure account fields"},
+ * {"var":"$user_id","type":"int","desc":"User ID"}]
+ * @change_log
+ * ["Since: 2.0"]
+ * @usage
+ *
+ * @example
+ *
+ */
+ $secure_fields = apply_filters( 'um_secure_account_fields', $account_fields, um_user( 'ID' ) );
if ( is_array( $secure_fields ) ) {
foreach ( $secure_fields as $tab_key => $fields ) {
@@ -184,6 +207,27 @@ function um_submit_account_errors_hook( $args ) {
unset( $changes['hide_in_members'] );
}
+ /**
+ * UM hook
+ *
+ * @type filter
+ * @title um_account_pre_updating_profile_array
+ * @description Change update profile data before saving
+ * @input_vars
+ * [{"var":"$changes","type":"array","desc":"Profile changes array"}]
+ * @change_log
+ * ["Since: 2.0"]
+ * @usage
+ *
+ * @example
+ *
+ */
$changes = apply_filters( 'um_account_pre_updating_profile_array', $changes );
// fired on account page, just before updating profile
diff --git a/includes/core/um-actions-ajax.php b/includes/core/um-actions-ajax.php
index 41e367ac..a8472e7d 100644
--- a/includes/core/um-actions-ajax.php
+++ b/includes/core/um-actions-ajax.php
@@ -2,23 +2,46 @@
// Exit if accessed directly
if ( ! defined( 'ABSPATH' ) ) exit;
+/**
+ * Run check if username exists
+ * @uses action hooks: wp_ajax_nopriv_ultimatemember_check_username_exists, wp_ajax_ultimatemember_check_username_exists
+ * @return boolean
+ */
+add_action('wp_ajax_nopriv_ultimatemember_check_username_exists', 'ultimatemember_check_username_exists');
+add_action('wp_ajax_ultimatemember_check_username_exists', 'ultimatemember_check_username_exists');
+function ultimatemember_check_username_exists() {
+ $username = isset($_REQUEST['username']) ? $_REQUEST['username'] : '';
+ $exists = username_exists( $username );
+
/**
- * Run check if username exists
- * @uses action hooks: wp_ajax_nopriv_ultimatemember_check_username_exists, wp_ajax_ultimatemember_check_username_exists
- * @return boolean
+ * UM hook
+ *
+ * @type filter
+ * @title um_validate_username_exists
+ * @description Change username exists validation
+ * @input_vars
+ * [{"var":"$exists","type":"bool","desc":"Exists?"},
+ * {"var":"$username","type":"string","desc":"Username"}]
+ * @change_log
+ * ["Since: 2.0"]
+ * @usage
+ *
+ * @example
+ *
*/
- add_action('wp_ajax_nopriv_ultimatemember_check_username_exists', 'ultimatemember_check_username_exists');
- add_action('wp_ajax_ultimatemember_check_username_exists', 'ultimatemember_check_username_exists');
- function ultimatemember_check_username_exists() {
- $username = isset($_REQUEST['username']) ? $_REQUEST['username'] : '';
- $exists = username_exists( $username );
- $exists = apply_filters( 'um_validate_username_exists', $exists, $username );
+ $exists = apply_filters( 'um_validate_username_exists', $exists, $username );
- if( $exists ) {
- echo 1;
- } else {
- echo 0;
- }
+ if ( $exists ) {
+ echo 1;
+ } else {
+ echo 0;
+ }
- die();
- }
\ No newline at end of file
+ die();
+}
\ No newline at end of file
diff --git a/includes/core/um-actions-form.php b/includes/core/um-actions-form.php
index 603b5900..d38c1a1a 100644
--- a/includes/core/um-actions-form.php
+++ b/includes/core/um-actions-form.php
@@ -148,6 +148,28 @@ if ( ! defined( 'ABSPATH' ) ) exit;
}
}
+ /**
+ * UM hook
+ *
+ * @type filter
+ * @title um_get_custom_field_array
+ * @description Extend custom field data on submit form error
+ * @input_vars
+ * [{"var":"$array","type":"array","desc":"Field data"},
+ * {"var":"$fields","type":"array","desc":"All fields"}]
+ * @change_log
+ * ["Since: 2.0"]
+ * @usage
+ *
+ * @example
+ *
+ */
$array = apply_filters( 'um_get_custom_field_array', $array, $fields );
if ( ! empty( $array['conditions'] ) ) {
diff --git a/includes/core/um-actions-login.php b/includes/core/um-actions-login.php
index 05083046..e9540467 100644
--- a/includes/core/um-actions-login.php
+++ b/includes/core/um-actions-login.php
@@ -65,8 +65,6 @@ if ( ! defined( 'ABSPATH' ) ) exit;
UM()->form()->add_error( 'user_password', __('Password is incorrect. Please try again.','ultimate-member') );
}
- // add a way for other plugins like wp limit login
- // to limit the login attempts
$user = apply_filters( 'authenticate', null, $user_name, $args['user_password'] );
$authenticate_user = apply_filters( 'wp_authenticate_user', $user_name, $args['user_password'] );
@@ -240,12 +238,78 @@ if ( ! defined( 'ABSPATH' ) ) exit;
if ( UM()->user()->preview == true && is_admin() ) return;
$primary_btn_word = $args['primary_btn_word'];
+ /**
+ * UM hook
+ *
+ * @type filter
+ * @title um_login_form_button_one
+ * @description Change Login Form Primary button
+ * @input_vars
+ * [{"var":"$primary_btn_word","type":"string","desc":"Button text"},
+ * {"var":"$args","type":"array","desc":"Login Form arguments"}]
+ * @change_log
+ * ["Since: 2.0"]
+ * @usage
+ *
+ * @example
+ *
+ */
$primary_btn_word = apply_filters('um_login_form_button_one', $primary_btn_word, $args );
$secondary_btn_word = $args['secondary_btn_word'];
+ /**
+ * UM hook
+ *
+ * @type filter
+ * @title um_login_form_button_two
+ * @description Change Login Form Secondary button
+ * @input_vars
+ * [{"var":"$secondary_btn_word","type":"string","desc":"Button text"},
+ * {"var":"$args","type":"array","desc":"Login Form arguments"}]
+ * @change_log
+ * ["Since: 2.0"]
+ * @usage
+ *
+ * @example
+ *
+ */
$secondary_btn_word = apply_filters('um_login_form_button_two', $secondary_btn_word, $args );
$secondary_btn_url = ( isset( $args['secondary_btn_url'] ) && $args['secondary_btn_url'] ) ? $args['secondary_btn_url'] : um_get_core_page('register');
+ /**
+ * UM hook
+ *
+ * @type filter
+ * @title um_login_form_button_two_url
+ * @description Change Login Form Secondary button URL
+ * @input_vars
+ * [{"var":"$secondary_btn_url","type":"string","desc":"Button URL"},
+ * {"var":"$args","type":"array","desc":"Login Form arguments"}]
+ * @change_log
+ * ["Since: 2.0"]
+ * @usage
+ *
+ * @example
+ *
+ */
$secondary_btn_url = apply_filters('um_login_form_button_two_url', $secondary_btn_url, $args );
?>
diff --git a/includes/core/um-actions-members.php b/includes/core/um-actions-members.php
index 4e21386d..d58a3765 100644
--- a/includes/core/um-actions-members.php
+++ b/includes/core/um-actions-members.php
@@ -17,8 +17,29 @@ if ( ! defined( 'ABSPATH' ) ) exit;
}
}
}
-
- $search_filters = apply_filters('um_frontend_member_search_filters',$search_filters);
+
+ /**
+ * UM hook
+ *
+ * @type filter
+ * @title um_frontend_member_search_filters
+ * @description Extend Member Directory Search filter
+ * @input_vars
+ * [{"var":"$search_filters","type":"array","desc":"Search Filters"}]
+ * @change_log
+ * ["Since: 2.0"]
+ * @usage
+ *
+ * @example
+ *
+ */
+ $search_filters = apply_filters( 'um_frontend_member_search_filters', $search_filters );
if ( $args['search'] == 1 && is_array( $search_filters ) ) { // search on
diff --git a/includes/core/um-actions-misc.php b/includes/core/um-actions-misc.php
index 02170d9f..f2ff60a0 100644
--- a/includes/core/um-actions-misc.php
+++ b/includes/core/um-actions-misc.php
@@ -41,9 +41,29 @@ if ( ! defined( 'ABSPATH' ) ) exit;
}
-
- $url = apply_filters('um_browser_url_redirect_to__filter', $url );
- if( ! empty( $url ) ){
+ /**
+ * UM hook
+ *
+ * @type filter
+ * @title um_browser_url_redirect_to__filter
+ * @description Add redirect to field to form and change URL for it
+ * @input_vars
+ * [{"var":"$url","type":"string","desc":"Redirect to URL"}]
+ * @change_log
+ * ["Since: 2.0"]
+ * @usage
+ *
+ * @example
+ *
+ */
+ $url = apply_filters( 'um_browser_url_redirect_to__filter', $url );
+ if ( ! empty( $url ) ) {
echo '
';
}
@@ -64,7 +84,29 @@ if ( ! defined( 'ABSPATH' ) ) exit;
switch( $_REQUEST['updated'] ) {
default:
- $success = apply_filters("um_custom_success_message_handler", $success, $_REQUEST['updated']);
+ /**
+ * UM hook
+ *
+ * @type filter
+ * @title um_custom_success_message_handler
+ * @description Add custom success message
+ * @input_vars
+ * [{"var":"$success","type":"string","desc":"Message"},
+ * {"var":"$updated","type":"array","desc":"Updated data"}]
+ * @change_log
+ * ["Since: 2.0"]
+ * @usage
+ *
+ * @example
+ *
+ */
+ $success = apply_filters( "um_custom_success_message_handler", $success, $_REQUEST['updated'] );
break;
case 'account':
@@ -86,9 +128,31 @@ if ( ! defined( 'ABSPATH' ) ) exit;
switch( $_REQUEST['err'] ) {
default:
- $err = apply_filters("um_custom_error_message_handler", $err, $_REQUEST['err']);
+ /**
+ * UM hook
+ *
+ * @type filter
+ * @title um_custom_error_message_handler
+ * @description Add custom error message
+ * @input_vars
+ * [{"var":"$error","type":"string","desc":"Error message"},
+ * {"var":"$request_error","type":"array","desc":"Error data"}]
+ * @change_log
+ * ["Since: 2.0"]
+ * @usage
+ *
+ * @example
+ *
+ */
+ $err = apply_filters( "um_custom_error_message_handler", $err, $_REQUEST['err'] );
if ( !$err )
- $err = __('An error has been encountered','ultimate-member');
+ $err = __( 'An error has been encountered', 'ultimate-member' );
break;
case 'registration_disabled':
diff --git a/includes/core/um-actions-profile.php b/includes/core/um-actions-profile.php
index b5c1631d..c75d17e3 100644
--- a/includes/core/um-actions-profile.php
+++ b/includes/core/um-actions-profile.php
@@ -13,9 +13,31 @@ if ( ! defined( 'ABSPATH' ) ) exit;
if ( ! UM()->options()->get( 'profile_tab_main' ) && ! isset( $_REQUEST['um_action'] ) )
return;
+ /**
+ * UM hook
+ *
+ * @type filter
+ * @title um_profile_can_view_main
+ * @description Check user can view profile
+ * @input_vars
+ * [{"var":"$view","type":"bool","desc":"Can view?"},
+ * {"var":"$user_id","type":"int","desc":"User profile ID"}]
+ * @change_log
+ * ["Since: 2.0"]
+ * @usage
+ *
+ * @example
+ *
+ */
$can_view = apply_filters( 'um_profile_can_view_main', -1, um_profile_id() );
- if ($can_view == -1) {
+ if ( $can_view == -1 ) {
do_action( "um_before_form", $args );
@@ -120,6 +142,27 @@ if ( ! defined( 'ABSPATH' ) ) exit;
do_action( 'um_user_pre_updating_profile', $to_update );
+ /**
+ * UM hook
+ *
+ * @type filter
+ * @title um_user_pre_updating_profile_array
+ * @description Change submitted data before update profile
+ * @input_vars
+ * [{"var":"$to_update","type":"array","desc":"Profile data upgrade"}]
+ * @change_log
+ * ["Since: 2.0"]
+ * @usage
+ *
+ * @example
+ *
+ */
$to_update = apply_filters( 'um_user_pre_updating_profile_array', $to_update );
@@ -128,6 +171,27 @@ if ( ! defined( 'ABSPATH' ) ) exit;
do_action( 'um_after_user_updated', um_user( 'ID' ), $args, $to_update );
}
+ /**
+ * UM hook
+ *
+ * @type filter
+ * @title um_user_pre_updating_files_array
+ * @description Change submitted files before update profile
+ * @input_vars
+ * [{"var":"$files","type":"array","desc":"Profile data files"}]
+ * @change_log
+ * ["Since: 2.0"]
+ * @usage
+ *
+ * @example
+ *
+ */
$files = apply_filters( 'um_user_pre_updating_files_array', $files );
if (is_array( $files )) {
@@ -377,6 +441,27 @@ if ( ! defined( 'ABSPATH' ) ) exit;
'
' . __( 'Cancel', 'ultimate-member' ) . '',
);
+ /**
+ * UM hook
+ *
+ * @type filter
+ * @title um_user_photo_menu_view
+ * @description Change user photo on menu view
+ * @input_vars
+ * [{"var":"$items","type":"array","desc":"User Photos"}]
+ * @change_log
+ * ["Since: 2.0"]
+ * @usage
+ *
+ * @example
+ *
+ */
$items = apply_filters( 'um_user_photo_menu_view', $items );
echo UM()->menu()->new_ui( 'bc', 'div.um-profile-photo', 'click', $items );
@@ -389,6 +474,27 @@ if ( ! defined( 'ABSPATH' ) ) exit;
'
' . __( 'Cancel', 'ultimate-member' ) . '',
);
+ /**
+ * UM hook
+ *
+ * @type filter
+ * @title um_user_photo_menu_edit
+ * @description Change user photo on menu edit
+ * @input_vars
+ * [{"var":"$items","type":"array","desc":"User Photos"}]
+ * @change_log
+ * ["Since: 2.0"]
+ * @usage
+ *
+ * @example
+ *
+ */
$items = apply_filters( 'um_user_photo_menu_edit', $items );
echo UM()->menu()->new_ui( 'bc', 'div.um-profile-photo', 'click', $items );
@@ -574,12 +680,55 @@ if ( ! defined( 'ABSPATH' ) ) exit;
$items = array_merge( $items, $actions );
}
+ /**
+ * UM hook
+ *
+ * @type filter
+ * @title um_profile_edit_menu_items
+ * @description Edit menu items on profile page
+ * @input_vars
+ * [{"var":"$items","type":"array","desc":"User Menu"},
+ * {"var":"$user_id","type":"int","desc":"Profile ID"}]
+ * @change_log
+ * ["Since: 2.0"]
+ * @usage
+ *
+ * @example
+ *
+ */
$items = apply_filters( 'um_profile_edit_menu_items', $items, um_profile_id() );
$items['cancel'] = $cancel;
} else {
+ /**
+ * UM hook
+ *
+ * @type filter
+ * @title um_myprofile_edit_menu_items
+ * @description Edit menu items on my profile page
+ * @input_vars
+ * [{"var":"$items","type":"array","desc":"User Menu"}]
+ * @change_log
+ * ["Since: 2.0"]
+ * @usage
+ *
+ * @example
+ *
+ */
$items = apply_filters( 'um_myprofile_edit_menu_items', $items );
}
@@ -673,6 +822,27 @@ if ( ! defined( 'ABSPATH' ) ) exit;
// get active tabs
$tabs = UM()->profile()->tabs_active();
+ /**
+ * UM hook
+ *
+ * @type filter
+ * @title um_user_profile_tabs
+ * @description Extend profile tabs
+ * @input_vars
+ * [{"var":"$tabs","type":"array","desc":"Profile Tabs"}]
+ * @change_log
+ * ["Since: 2.0"]
+ * @usage
+ *
+ * @example
+ *
+ */
$tabs = apply_filters( 'um_user_profile_tabs', $tabs );
UM()->user()->tabs = $tabs;
@@ -710,6 +880,27 @@ if ( ! defined( 'ABSPATH' ) ) exit;
$nav_link = remove_query_arg( 'subnav', $nav_link );
$nav_link = add_query_arg( 'profiletab', $id, $nav_link );
+ /**
+ * UM hook
+ *
+ * @type filter
+ * @title um_profile_menu_link_{$id}
+ * @description Change profile menu link by tab $id
+ * @input_vars
+ * [{"var":"$nav_link","type":"string","desc":"Profile Tab Link"}]
+ * @change_log
+ * ["Since: 2.0"]
+ * @usage
+ *
+ * @example
+ *
+ */
$nav_link = apply_filters( "um_profile_menu_link_{$id}", $nav_link );
?>
diff --git a/includes/core/um-actions-register.php b/includes/core/um-actions-register.php
index 62d5debd..0f671879 100644
--- a/includes/core/um-actions-register.php
+++ b/includes/core/um-actions-register.php
@@ -149,6 +149,27 @@ if ( ! defined( 'ABSPATH' ) ) exit;
if ( isset( UM()->form()->errors ) )
return false;
+ /**
+ * UM hook
+ *
+ * @type filter
+ * @title um_add_user_frontend_submitted
+ * @description Extend user data on registration form submit
+ * @input_vars
+ * [{"var":"$submitted","type":"array","desc":"Registration data"}]
+ * @change_log
+ * ["Since: 2.0"]
+ * @usage
+ *
+ * @example
+ *
+ */
$args = apply_filters( 'um_add_user_frontend_submitted', $args );
extract( $args );
@@ -198,6 +219,27 @@ if ( ! defined( 'ABSPATH' ) ) exit;
if ( ! isset( $user_email ) ) {
$site_url = @$_SERVER['SERVER_NAME'];
$user_email = 'nobody' . $unique_userID . '@' . $site_url;
+ /**
+ * UM hook
+ *
+ * @type filter
+ * @title um_user_register_submitted__email
+ * @description Change user default email if it's empty on registration
+ * @input_vars
+ * [{"var":"$user_email","type":"string","desc":"Default email"}]
+ * @change_log
+ * ["Since: 2.0"]
+ * @usage
+ *
+ * @example
+ *
+ */
$user_email = apply_filters( 'um_user_register_submitted__email', $user_email );
}
@@ -210,6 +252,28 @@ if ( ! defined( 'ABSPATH' ) ) exit;
$args['submitted'] = array_merge( $args['submitted'], $credentials );
$args = array_merge( $args, $credentials );
+ /**
+ * UM hook
+ *
+ * @type filter
+ * @title um_registration_user_role
+ * @description Change user role on registration process
+ * @input_vars
+ * [{"var":"$role","type":"string","desc":"User role"},
+ * {"var":"$submitted","type":"array","desc":"Registration data"}]
+ * @change_log
+ * ["Since: 2.0"]
+ * @usage
+ *
+ * @example
+ *
+ */
$user_role = apply_filters( 'um_registration_user_role', UM()->form()->assigned_role( UM()->form()->form_id ), $args );
$userdata = array(
@@ -245,6 +309,27 @@ if ( ! defined( 'ABSPATH' ) ) exit;
if( empty( $role ) ) return;
+ /**
+ * UM hook
+ *
+ * @type filter
+ * @title um_register_hidden_role_field
+ * @description Display hidden role field
+ * @input_vars
+ * [{"var":"$role","type":"string","desc":"Hidden user role"}]
+ * @change_log
+ * ["Since: 2.0"]
+ * @usage
+ *
+ * @example
+ *
+ */
$role = apply_filters('um_register_hidden_role_field', $role );
if( $role ){
echo '
';
@@ -261,12 +346,78 @@ if ( ! defined( 'ABSPATH' ) ) exit;
if ( isset( UM()->user()->preview ) && UM()->user()->preview == true && is_admin() ) return;
$primary_btn_word = $args['primary_btn_word'];
+ /**
+ * UM hook
+ *
+ * @type filter
+ * @title um_register_form_button_one
+ * @description Change Register Form Primary button
+ * @input_vars
+ * [{"var":"$primary_btn_word","type":"string","desc":"Button text"},
+ * {"var":"$args","type":"array","desc":"Registration Form arguments"}]
+ * @change_log
+ * ["Since: 2.0"]
+ * @usage
+ *
+ * @example
+ *
+ */
$primary_btn_word = apply_filters('um_register_form_button_one', $primary_btn_word, $args );
$secondary_btn_word = $args['secondary_btn_word'];
+ /**
+ * UM hook
+ *
+ * @type filter
+ * @title um_register_form_button_two
+ * @description Change Registration Form Secondary button
+ * @input_vars
+ * [{"var":"$secondary_btn_word","type":"string","desc":"Button text"},
+ * {"var":"$args","type":"array","desc":"Registration Form arguments"}]
+ * @change_log
+ * ["Since: 2.0"]
+ * @usage
+ *
+ * @example
+ *
+ */
$secondary_btn_word = apply_filters('um_register_form_button_two', $secondary_btn_word, $args );
$secondary_btn_url = ( isset( $args['secondary_btn_url'] ) && $args['secondary_btn_url'] ) ? $args['secondary_btn_url'] : um_get_core_page('login');
+ /**
+ * UM hook
+ *
+ * @type filter
+ * @title um_register_form_button_two_url
+ * @description Change Registration Form Secondary button URL
+ * @input_vars
+ * [{"var":"$secondary_btn_url","type":"string","desc":"Button URL"},
+ * {"var":"$args","type":"array","desc":"Registration Form arguments"}]
+ * @change_log
+ * ["Since: 2.0"]
+ * @usage
+ *
+ * @example
+ *
+ */
$secondary_btn_url = apply_filters('um_register_form_button_two_url', $secondary_btn_url, $args );
?>
@@ -332,6 +483,27 @@ if ( ! defined( 'ABSPATH' ) ) exit;
}
}
+ /**
+ * UM hook
+ *
+ * @type filter
+ * @title um_user_pre_updating_files_array
+ * @description Change submitted files before register new user
+ * @input_vars
+ * [{"var":"$files","type":"array","desc":"Profile data files"}]
+ * @change_log
+ * ["Since: 2.0"]
+ * @usage
+ *
+ * @example
+ *
+ */
$files = apply_filters( 'um_user_pre_updating_files_array', $files );
if ( !empty( $files ) ) {
diff --git a/includes/core/um-filters-account.php b/includes/core/um-filters-account.php
index eff446d1..2a2ed8ec 100644
--- a/includes/core/um-filters-account.php
+++ b/includes/core/um-filters-account.php
@@ -12,7 +12,28 @@ if ( ! defined( 'ABSPATH' ) ) exit;
*/
add_filter('um_account_secure_fields','um_account_secure_fields', 10, 2);
function um_account_secure_fields( $fields, $tab_key ){
- $secure = apply_filters('um_account_secure_fields__enabled', true );
+ /**
+ * UM hook
+ *
+ * @type filter
+ * @title um_account_secure_fields__enabled
+ * @description Active account secure fields
+ * @input_vars
+ * [{"var":"$enabled","type":"string","desc":"Enable secure account fields"}]
+ * @change_log
+ * ["Since: 2.0"]
+ * @usage
+ *
+ * @example
+ *
+ */
+ $secure = apply_filters( 'um_account_secure_fields__enabled', true );
if( ! $secure ) return $fields;
diff --git a/includes/core/um-filters-avatars.php b/includes/core/um-filters-avatars.php
index f0322183..77e22db1 100644
--- a/includes/core/um-filters-avatars.php
+++ b/includes/core/um-filters-avatars.php
@@ -39,7 +39,28 @@ if ( ! defined( 'ABSPATH' ) ) exit;
$avatar = um_user('profile_photo', $size);
- $image_alt = apply_filters("um_avatar_image_alternate_text", um_user("display_name") );
+ /**
+ * UM hook
+ *
+ * @type filter
+ * @title um_avatar_image_alternate_text
+ * @description Change avatar image alt
+ * @input_vars
+ * [{"var":"$avatar_alt","type":"string","desc":"Image alternate text. Display name by default"}]
+ * @change_log
+ * ["Since: 2.0"]
+ * @usage
+ *
+ * @example
+ *
+ */
+ $image_alt = apply_filters( "um_avatar_image_alternate_text", um_user("display_name") );
if ( ! $avatar && UM()->options()->get( 'use_gravatars' ) ) {
diff --git a/includes/core/um-filters-fields.php b/includes/core/um-filters-fields.php
index 0c2b527c..8fdff6af 100644
--- a/includes/core/um-filters-fields.php
+++ b/includes/core/um-filters-fields.php
@@ -206,8 +206,8 @@ if ( ! defined( 'ABSPATH' ) ) exit;
/***
*** @global
***/
- add_filter('um_profile_field_filter_hook__', 'um_profile_field_filter_hook__', 99, 2);
- function um_profile_field_filter_hook__( $value, $data ) {
+ add_filter('um_profile_field_filter_hook__', 'um_profile_field_filter_hook__', 99, 3 );
+ function um_profile_field_filter_hook__( $value, $data, $type = '' ) {
if ( !$value ) return '';
if ( ( isset( $data['validate'] ) && $data['validate'] != '' && strstr( $data['validate'], 'url' ) ) || ( isset( $data['type'] ) && $data['type'] == 'url' ) ) {
@@ -322,8 +322,8 @@ if ( ! defined( 'ABSPATH' ) ) exit;
* @return mixed
* @uses hook filter: um_profile_field_filter_hook__
*/
- add_filter('um_profile_field_filter_hook__','um_force_utf8_fields', 10, 2 );
- function um_force_utf8_fields( $value, $data ) {
+ add_filter('um_profile_field_filter_hook__','um_force_utf8_fields', 9, 3 );
+ function um_force_utf8_fields( $value, $data, $type = '' ) {
if( ! UM()->options()->get('um_force_utf8_strings') )
return $value;
@@ -470,7 +470,7 @@ if ( ! defined( 'ABSPATH' ) ) exit;
* @return string $value
* @uses hook filters: um_profile_field_filter_hook__
*/
-function um_profile_field_filter_xss_validation( $value, $data, $type ) {
+function um_profile_field_filter_xss_validation( $value, $data, $type = '' ) {
if ( ! empty( $value ) && is_string( $value ) ) {
$value = stripslashes( $value );
$data['validate'] = isset( $data['validate'] ) ? $data['validate'] : '';
diff --git a/includes/core/um-filters-files.php b/includes/core/um-filters-files.php
index 40d951c6..166846e8 100644
--- a/includes/core/um-filters-files.php
+++ b/includes/core/um-filters-files.php
@@ -3,23 +3,67 @@
if ( ! defined( 'ABSPATH' ) ) exit;
- /***
- *** @Support multisite
- ***/
- add_filter('um_upload_basedir_filter','um_multisite_urls_support', 99 );
- add_filter('um_upload_baseurl_filter','um_multisite_urls_support', 99 );
- function um_multisite_urls_support( $dir ) {
-
- if ( is_multisite() ) { // Need to the work
-
- if ( get_current_blog_id() == '1' ) return $dir;
-
- $sites_dir = apply_filters('um_multisite_upload_sites_directory', 'sites/' );
- $split = explode( $sites_dir, $dir );
- $um_dir = apply_filters('um_multisite_upload_directory','ultimatemember/');
- $dir = $split[0] . $um_dir;
+/***
+*** @Support multisite
+***/
+add_filter('um_upload_basedir_filter','um_multisite_urls_support', 99 );
+add_filter('um_upload_baseurl_filter','um_multisite_urls_support', 99 );
+function um_multisite_urls_support( $dir ) {
+ if ( is_multisite() ) { // Need to the work
+
+ if ( get_current_blog_id() == '1' ) {
+ return $dir;
}
- return $dir;
- }
\ No newline at end of file
+ /**
+ * UM hook
+ *
+ * @type filter
+ * @title um_multisite_upload_sites_directory
+ * @description Change multisite uploads directory
+ * @input_vars
+ * [{"var":"$sites_dir","type":"string","desc":"Upload sites directory"}]
+ * @change_log
+ * ["Since: 2.0"]
+ * @usage
+ *
+ * @example
+ *
+ */
+ $sites_dir = apply_filters('um_multisite_upload_sites_directory', 'sites/' );
+ $split = explode( $sites_dir, $dir );
+ /**
+ * UM hook
+ *
+ * @type filter
+ * @title um_multisite_upload_directory
+ * @description Change multisite UM uploads directory
+ * @input_vars
+ * [{"var":"$um_dir","type":"string","desc":"Upload UM directory"}]
+ * @change_log
+ * ["Since: 2.0"]
+ * @usage
+ *
+ * @example
+ *
+ */
+ $um_dir = apply_filters('um_multisite_upload_directory','ultimatemember/');
+ $dir = $split[0] . $um_dir;
+
+ }
+
+ return $dir;
+}
\ No newline at end of file
diff --git a/includes/core/um-filters-members.php b/includes/core/um-filters-members.php
index e6adde06..8d415dfd 100644
--- a/includes/core/um-filters-members.php
+++ b/includes/core/um-filters-members.php
@@ -151,6 +151,27 @@ if ( ! defined( 'ABSPATH' ) ) exit;
'relation' => 'OR',
);
+ /**
+ * UM hook
+ *
+ * @type filter
+ * @title um_query_args_{$field}__filter
+ * @description Change field's query for search at Members Directory
+ * @input_vars
+ * [{"var":"$field_query","type":"array","desc":"Field query"}]
+ * @change_log
+ * ["Since: 2.0"]
+ * @usage
+ *
+ * @example
+ *
+ */
$field_query = apply_filters( "um_query_args_{$field}__filter", $field_query );
$query_args['meta_query'][] = $field_query;
}
@@ -164,7 +185,27 @@ if ( ! defined( 'ABSPATH' ) ) exit;
}
- // allow filtering
+ /**
+ * UM hook
+ *
+ * @type filter
+ * @title um_query_args_filter
+ * @description Change query for search at Members Directory
+ * @input_vars
+ * [{"var":"$query_args","type":"array","desc":"Query Arguments"}]
+ * @change_log
+ * ["Since: 2.0"]
+ * @usage
+ *
+ * @example
+ *
+ */
$query_args = apply_filters( 'um_query_args_filter', $query_args );
if ( count( $query_args['meta_query'] ) == 1 )
@@ -293,6 +334,28 @@ if ( ! defined( 'ABSPATH' ) ) exit;
$query_args['order'] = $order;
}
+ /**
+ * UM hook
+ *
+ * @type filter
+ * @title um_modify_sortby_parameter
+ * @description Change query sort by attributes for search at Members Directory
+ * @input_vars
+ * [{"var":"$query_args","type":"array","desc":"Query Arguments"},
+ * {"var":"$sortby","type":"string","desc":"Sort by"}]
+ * @change_log
+ * ["Since: 2.0"]
+ * @usage
+ *
+ * @example
+ *
+ */
$query_args = apply_filters('um_modify_sortby_parameter', $query_args, $sortby);
}
diff --git a/includes/core/um-filters-navmenu.php b/includes/core/um-filters-navmenu.php
index 137643e6..e28ee615 100644
--- a/includes/core/um-filters-navmenu.php
+++ b/includes/core/um-filters-navmenu.php
@@ -75,7 +75,28 @@ if ( ! is_admin() ) {
}
- // add filter to work with plugins that don't use traditional roles
+ /**
+ * UM hook
+ *
+ * @type filter
+ * @title um_nav_menu_roles_item_visibility
+ * @description Add filter to work with plugins that don't use traditional roles
+ * @input_vars
+ * [{"var":"$visible","type":"bool","desc":"Visible?"},
+ * {"var":"$item","type":"object","desc":"Menu Item"}]
+ * @change_log
+ * ["Since: 2.0"]
+ * @usage
+ *
+ * @example
+ *
+ */
$visible = apply_filters( 'um_nav_menu_roles_item_visibility', $visible, $item );
// unset non-visible item
diff --git a/includes/core/um-filters-user.php b/includes/core/um-filters-user.php
index 08c51006..6c038a0d 100644
--- a/includes/core/um-filters-user.php
+++ b/includes/core/um-filters-user.php
@@ -92,11 +92,31 @@ function um_clean_user_basename_filter( $value, $raw ){
}
}
-
- $value = apply_filters("um_permalink_base_before_filter", $value );
+ /**
+ * UM hook
+ *
+ * @type filter
+ * @title um_permalink_base_before_filter
+ * @description Base permalink before
+ * @input_vars
+ * [{"var":"$permalink","type":"string","desc":"User Permalink"}]
+ * @change_log
+ * ["Since: 2.0"]
+ * @usage
+ *
+ * @example
+ *
+ */
+ $value = apply_filters( "um_permalink_base_before_filter", $value );
$raw_value = $value;
- switch( $permalink_base ){
+ switch( $permalink_base ) {
case 'name':
@@ -112,6 +132,28 @@ function um_clean_user_basename_filter( $value, $raw ){
$value = str_replace( '.', ' ', $value );
}
+ /**
+ * UM hook
+ *
+ * @type filter
+ * @title um_permalink_base_after_filter_name
+ * @description Base permalink after if permalink is username
+ * @input_vars
+ * [{"var":"$permalink","type":"string","desc":"User Permalink"},
+ * {"var":"$raw_permalink","type":"string","desc":"RAW User Permalink"}]
+ * @change_log
+ * ["Since: 2.0"]
+ * @usage
+ *
+ * @example
+ *
+ */
$value = apply_filters("um_permalink_base_after_filter_name", $value, $raw_value );
break;
@@ -131,6 +173,28 @@ function um_clean_user_basename_filter( $value, $raw ){
$value = str_replace( '_', '-', $value );
}
+ /**
+ * UM hook
+ *
+ * @type filter
+ * @title um_permalink_base_after_filter_name_dash
+ * @description Base permalink after if permalink is first name - last name
+ * @input_vars
+ * [{"var":"$permalink","type":"string","desc":"User Permalink"},
+ * {"var":"$raw_permalink","type":"string","desc":"RAW User Permalink"}]
+ * @change_log
+ * ["Since: 2.0"]
+ * @usage
+ *
+ * @example
+ *
+ */
$value = apply_filters("um_permalink_base_after_filter_name_dash", $value, $raw_value );
break;
@@ -146,6 +210,28 @@ function um_clean_user_basename_filter( $value, $raw ){
$value = str_replace( '_', '+', $value );
}
+ /**
+ * UM hook
+ *
+ * @type filter
+ * @title um_permalink_base_after_filter_name_plus
+ * @description Base permalink after if permalink is first name + last name
+ * @input_vars
+ * [{"var":"$permalink","type":"string","desc":"User Permalink"},
+ * {"var":"$raw_permalink","type":"string","desc":"RAW User Permalink"}]
+ * @change_log
+ * ["Since: 2.0"]
+ * @usage
+ *
+ * @example
+ *
+ */
$value = apply_filters("um_permalink_base_after_filter_name_plus", $value, $raw_value );
break;
@@ -157,6 +243,28 @@ function um_clean_user_basename_filter( $value, $raw ){
$value = str_replace( '_', '-', $value );
}
+ /**
+ * UM hook
+ *
+ * @type filter
+ * @title um_permalink_base_after_filter
+ * @description Base permalink after for default permalink
+ * @input_vars
+ * [{"var":"$permalink","type":"string","desc":"User Permalink"},
+ * {"var":"$raw_permalink","type":"string","desc":"RAW User Permalink"}]
+ * @change_log
+ * ["Since: 2.0"]
+ * @usage
+ *
+ * @example
+ *
+ */
$value = apply_filters("um_permalink_base_after_filter", $value, $raw_value );
break;
diff --git a/includes/lib/upload/um-file-upload.php b/includes/lib/upload/um-file-upload.php
index a4002421..2fdbc636 100644
--- a/includes/lib/upload/um-file-upload.php
+++ b/includes/lib/upload/um-file-upload.php
@@ -39,7 +39,28 @@ $timestamp = $_POST['timestamp'];
UM()->fields()->set_id = $_POST['set_id'];
UM()->fields()->set_mode = $_POST['set_mode'];
-$um_file_upload_nonce = apply_filters("um_file_upload_nonce", true );
+/**
+ * UM hook
+ *
+ * @type filter
+ * @title um_file_upload_nonce
+ * @description Change File Upload nonce
+ * @input_vars
+ * [{"var":"$nonce","type":"bool","desc":"Nonce"}]
+ * @change_log
+ * ["Since: 2.0"]
+ * @usage
+ *
+ * @example
+ *
+ */
+$um_file_upload_nonce = apply_filters( "um_file_upload_nonce", true );
if( $um_file_upload_nonce ){
if ( ! wp_verify_nonce( $nonce, 'um_upload_nonce-'.$timestamp ) && is_user_logged_in()) {
@@ -56,9 +77,33 @@ if(isset($_FILES[$id]['name'])) {
if(!is_array($_FILES[$id]['name'])) {
$temp = $_FILES[$id]["tmp_name"];
- $file = apply_filters('um_upload_file_name',$id."-".$_FILES[$id]["name"],$id,$_FILES[$id]["name"]);
- $file = sanitize_file_name($file);
- $extension = strtolower( pathinfo($file, PATHINFO_EXTENSION) );
+
+ /**
+ * UM hook
+ *
+ * @type filter
+ * @title um_upload_file_name
+ * @description Change File Upload nonce
+ * @input_vars
+ * [{"var":"$filename","type":"string","desc":"Filename"},
+ * {"var":"$id","type":"int","desc":"ID"},
+ * {"var":"$name","type":"string","desc":"Name"}]
+ * @change_log
+ * ["Since: 2.0"]
+ * @usage
+ *
+ * @example
+ *
+ */
+ $file = apply_filters( 'um_upload_file_name', $id . "-" . $_FILES[ $id ]["name"], $id, $_FILES[ $id ]["name"] );
+ $file = sanitize_file_name( $file );
+ $extension = strtolower( pathinfo( $file, PATHINFO_EXTENSION ) );
$error = UM()->files()->check_file_upload( $temp, $extension, $id );
if ( $error ){
diff --git a/includes/lib/upload/um-image-upload.php b/includes/lib/upload/um-image-upload.php
index 5abffbc7..0e003a18 100644
--- a/includes/lib/upload/um-image-upload.php
+++ b/includes/lib/upload/um-image-upload.php
@@ -33,7 +33,28 @@ $nonce = $_POST['_wpnonce'];
UM()->fields()->set_id = $_POST['set_id'];
UM()->fields()->set_mode = $_POST['set_mode'];
-$um_image_upload_nonce = apply_filters("um_image_upload_nonce", true );
+/**
+ * UM hook
+ *
+ * @type filter
+ * @title um_image_upload_nonce
+ * @description Change Image Upload nonce
+ * @input_vars
+ * [{"var":"$nonce","type":"bool","desc":"Nonce"}]
+ * @change_log
+ * ["Since: 2.0"]
+ * @usage
+ *
+ * @example
+ *
+ */
+$um_image_upload_nonce = apply_filters( "um_image_upload_nonce", true );
if( $um_image_upload_nonce ){
if ( ! wp_verify_nonce( $nonce, 'um_upload_nonce-'.$timestamp ) && is_user_logged_in() ) {
diff --git a/includes/um-short-functions.php b/includes/um-short-functions.php
index cc56842c..370b4224 100644
--- a/includes/um-short-functions.php
+++ b/includes/um-short-functions.php
@@ -76,6 +76,27 @@ function um_clean_user_basename( $value ) {
$value = str_replace( '-', ' ', $value );
$value = str_replace( '+', ' ', $value );
+ /**
+ * UM hook
+ *
+ * @type filter
+ * @title um_clean_user_basename_filter
+ * @description Change clean user basename
+ * @input_vars
+ * [{"var":"$basename","type":"string","desc":"User basename"},
+ * {"var":"$raw_basename","type":"string","desc":"RAW user basename"}]
+ * @change_log
+ * ["Since: 2.0"]
+ * @usage add_filter( 'um_clean_user_basename_filter', 'function_name', 10, 2 );
+ * @example
+ *
+ */
$value = apply_filters( 'um_clean_user_basename_filter', $value, $raw_value );
return $value;
@@ -113,6 +134,27 @@ function um_convert_tags( $content, $args = array(), $with_kses = true ) {
'{user_avatar_url}',
);
+ /**
+ * UM hook
+ *
+ * @type filter
+ * @title um_template_tags_patterns_hook
+ * @description Extend UM placeholders
+ * @input_vars
+ * [{"var":"$placeholders","type":"array","desc":"UM Placeholders"}]
+ * @change_log
+ * ["Since: 2.0"]
+ * @usage add_filter( 'um_template_tags_patterns_hook', 'function_name', 10, 1 );
+ * @example
+ *
+ */
$search = apply_filters( 'um_template_tags_patterns_hook', $search );
$replace = array(
@@ -136,6 +178,27 @@ function um_convert_tags( $content, $args = array(), $with_kses = true ) {
um_get_user_avatar_url(),
);
+ /**
+ * UM hook
+ *
+ * @type filter
+ * @title um_template_tags_replaces_hook
+ * @description Extend UM replace placeholders
+ * @input_vars
+ * [{"var":"$replace_placeholders","type":"array","desc":"UM Replace Placeholders"}]
+ * @change_log
+ * ["Since: 2.0"]
+ * @usage add_filter( 'um_template_tags_replaces_hook', 'function_name', 10, 1 );
+ * @example
+ *
+ */
$replace = apply_filters( 'um_template_tags_replaces_hook', $replace );
$content = str_replace( $search, $replace, $content );
@@ -193,6 +256,26 @@ function um_user_ip() {
$ip = $_SERVER['REMOTE_ADDR'];
}
+ /**
+ * UM hook
+ *
+ * @type filter
+ * @title um_user_ip
+ * @description Change User IP
+ * @input_vars
+ * [{"var":"$ip","type":"string","desc":"User IP"}]
+ * @change_log
+ * ["Since: 2.0"]
+ * @usage add_filter( 'um_user_ip', 'function_name', 10, 1 );
+ * @example
+ *
+ */
return apply_filters( 'um_user_ip', $ip );
}
@@ -430,6 +513,26 @@ function um_user_submitted_registration( $style = false ) {
if (isset( $data ) && is_array( $data )) {
+ /**
+ * UM hook
+ *
+ * @type filter
+ * @title um_email_registration_data
+ * @description Prepare Registration data to email
+ * @input_vars
+ * [{"var":"$data","type":"array","desc":"Registration Data"}]
+ * @change_log
+ * ["Since: 2.0"]
+ * @usage add_filter( 'um_email_registration_data', 'function_name', 10, 1 );
+ * @example
+ *
+ */
$data = apply_filters( 'um_email_registration_data', $data );
foreach ($data as $k => $v) {
@@ -510,8 +613,74 @@ function um_filtered_value( $key, $data = false ) {
$type = ( isset( $data['type'] ) ) ? $data['type'] : '';
+ /**
+ * UM hook
+ *
+ * @type filter
+ * @title um_profile_field_filter_hook__
+ * @description Change or filter field value
+ * @input_vars
+ * [{"var":"$value","type":"string","desc":"Field Value"},
+ * {"var":"$data","type":"array","desc":"Field Data"},
+ * {"var":"$type","type":"string","desc":"Field Type"}]
+ * @change_log
+ * ["Since: 2.0"]
+ * @usage add_filter( 'um_profile_field_filter_hook__', 'function_name', 10, 3 );
+ * @example
+ *
+ */
$value = apply_filters( "um_profile_field_filter_hook__", $value, $data, $type );
+
+ /**
+ * UM hook
+ *
+ * @type filter
+ * @title um_profile_field_filter_hook__{$key}
+ * @description Change or filter field value by field key ($key)
+ * @input_vars
+ * [{"var":"$value","type":"string","desc":"Field Value"},
+ * {"var":"$data","type":"array","desc":"Field Data"}]
+ * @change_log
+ * ["Since: 2.0"]
+ * @usage add_filter( 'um_profile_field_filter_hook__{$key}', 'function_name', 10, 2 );
+ * @example
+ *
+ */
$value = apply_filters( "um_profile_field_filter_hook__{$key}", $value, $data );
+
+ /**
+ * UM hook
+ *
+ * @type filter
+ * @title um_profile_field_filter_hook__{$type}
+ * @description Change or filter field value by field type ($type)
+ * @input_vars
+ * [{"var":"$value","type":"string","desc":"Field Value"},
+ * {"var":"$data","type":"array","desc":"Field Data"}]
+ * @change_log
+ * ["Since: 2.0"]
+ * @usage add_filter( 'um_profile_field_filter_hook__{$type}', 'function_name', 10, 2 );
+ * @example
+ *
+ */
$value = apply_filters( "um_profile_field_filter_hook__{$type}", $value, $data );
$value = UM()->shortcodes()->emotize( $value );
return $value;
@@ -652,6 +821,28 @@ function um_get_core_page( $slug, $updated = false ) {
$url = add_query_arg( 'updated', esc_attr( $updated ), $url );
}
+ /**
+ * UM hook
+ *
+ * @type filter
+ * @title um_get_core_page_filter
+ * @description Change UM core page URL
+ * @input_vars
+ * [{"var":"$url","type":"string","desc":"UM Page URL"},
+ * {"var":"$slug","type":"string","desc":"UM Page slug"},
+ * {"var":"$updated","type":"bool","desc":"Additional parameter"}]
+ * @change_log
+ * ["Since: 2.0"]
+ * @usage add_filter( 'um_get_core_page_filter', 'function_name', 10, 3 );
+ * @example
+ *
+ */
return apply_filters( 'um_get_core_page_filter', $url, $slug, $updated );
}
@@ -759,6 +950,28 @@ function um_select_if_in_query_params( $filter, $val ) {
if (isset( $query[$filter] ) && $val == $query[$filter])
$selected = true;
+ /**
+ * UM hook
+ *
+ * @type filter
+ * @title um_selected_if_in_query_params
+ * @description Make selected or unselected from query attribute
+ * @input_vars
+ * [{"var":"$selected","type":"bool","desc":"Selected or not"},
+ * {"var":"$filter","type":"string","desc":"Check by this filter in query"},
+ * {"var":"$val","type":"string","desc":"Field Value"}]
+ * @change_log
+ * ["Since: 2.0"]
+ * @usage add_filter( 'um_selected_if_in_query_params', 'function_name', 10, 3 );
+ * @example
+ *
+ */
$selected = apply_filters( 'um_selected_if_in_query_params', $selected, $filter, $val );
}
@@ -965,6 +1178,26 @@ function um_edit_my_profile_cancel_uri( $url = '' ) {
$url = add_query_arg( 'profiletab', 'main', $url );
}
+ /**
+ * UM hook
+ *
+ * @type filter
+ * @title um_edit_profile_cancel_uri
+ * @description Change Edit Profile Cancel URL
+ * @input_vars
+ * [{"var":"$url","type":"string","desc":"Cancel URL"}]
+ * @change_log
+ * ["Since: 2.0"]
+ * @usage add_filter( 'um_edit_profile_cancel_uri', 'function_name', 10, 1 );
+ * @example
+ *
+ */
$url = apply_filters( 'um_edit_profile_cancel_uri', $url );
return $url;
@@ -1228,14 +1461,53 @@ function um_fetch_user( $user_id ) {
*/
function um_profile( $key ) {
- if (!empty( UM()->user()->profile[$key] )) {
- $value = apply_filters( "um_profile_{$key}__filter", UM()->user()->profile[$key] );
+ if ( ! empty( UM()->user()->profile[ $key ] ) ) {
+ /**
+ * UM hook
+ *
+ * @type filter
+ * @title um_profile_{$key}__filter
+ * @description Change not empty profile field value
+ * @input_vars
+ * [{"var":"$value","type":"mixed","desc":"Profile Value"}]
+ * @change_log
+ * ["Since: 2.0"]
+ * @usage add_filter( 'um_profile_{$key}__filter', 'function_name', 10, 1 );
+ * @example
+ *
+ */
+ $value = apply_filters( "um_profile_{$key}__filter", UM()->user()->profile[ $key ] );
} else {
+ /**
+ * UM hook
+ *
+ * @type filter
+ * @title um_profile_{$key}_empty__filter
+ * @description Change Profile field value if it's empty
+ * @input_vars
+ * [{"var":"$value","type":"mixed","desc":"Profile Value"}]
+ * @change_log
+ * ["Since: 2.0"]
+ * @usage add_filter( 'um_profile_{$key}_empty__filter', 'function_name', 10, 1 );
+ * @example
+ *
+ */
$value = apply_filters( "um_profile_{$key}_empty__filter", false );
}
return $value;
-
}
@@ -1366,6 +1638,27 @@ function um_get_avatar_uri( $image, $attrs ) {
$find = false;
$ext = '.' . pathinfo( $image, PATHINFO_EXTENSION );
+ /**
+ * UM hook
+ *
+ * @type filter
+ * @title um_filter_avatar_cache_time
+ * @description Change Profile field value if it's empty
+ * @input_vars
+ * [{"var":"$timestamp","type":"timestamp","desc":"Avatar cache time"},
+ * {"var":"$user_id","type":"int","desc":"User ID"}]
+ * @change_log
+ * ["Since: 2.0"]
+ * @usage add_filter( 'um_filter_avatar_cache_time', 'function_name', 10, 2 );
+ * @example
+ *
+ */
$cache_time = apply_filters( 'um_filter_avatar_cache_time', current_time( 'timestamp' ), um_user( 'ID' ) );
if (!empty( $cache_time )) {
@@ -1450,11 +1743,30 @@ function um_get_user_avatar_url() {
*/
function um_get_default_cover_uri() {
$uri = UM()->options()->get( 'default_cover' );
- $uri = !empty( $uri['url'] ) ? $uri['url'] : '';
- if ($uri) {
- $uri = apply_filters( 'um_get_default_cover_uri_filter', $uri );
+ $uri = ! empty( $uri['url'] ) ? $uri['url'] : '';
+ if ( $uri ) {
- return $uri;
+ /**
+ * UM hook
+ *
+ * @type filter
+ * @title um_get_default_cover_uri_filter
+ * @description Change Default Cover URL
+ * @input_vars
+ * [{"var":"$uri","type":"string","desc":"Default Cover URL"}]
+ * @change_log
+ * ["Since: 2.0"]
+ * @usage add_filter( 'um_get_default_cover_uri_filter', 'function_name', 10, 1 );
+ * @example
+ *
+ */
+ return apply_filters( 'um_get_default_cover_uri_filter', $uri );
}
return '';
@@ -1509,6 +1821,26 @@ function um_user( $data, $attrs = null ) {
$name = implode( '-', array_map( 'ucfirst', explode( '-', $name ) ) );
}
+ /**
+ * UM hook
+ *
+ * @type filter
+ * @title um_user_{$data}_case
+ * @description Change user name on um_user function
+ * @input_vars
+ * [{"var":"$name","type":"string","desc":"User Name"}]
+ * @change_log
+ * ["Since: 2.0"]
+ * @usage add_filter( 'um_user_{$data}_case', 'function_name', 10, 1 );
+ * @example
+ *
+ */
$name = apply_filters( "um_user_{$data}_case", $name );
return $name;
@@ -1640,6 +1972,28 @@ function um_user( $data, $attrs = null ) {
$name = implode( '-', array_map( 'ucfirst', explode( '-', $name ) ) );
}
+ /**
+ * UM hook
+ *
+ * @type filter
+ * @title um_user_display_name_filter
+ * @description Change user display name on um_user function
+ * @input_vars
+ * [{"var":"$name","type":"string","desc":"User Name"},
+ * {"var":"$user_id","type":"int","desc":"User ID"},
+ * {"var":"$html","type":"bool","desc":"Is HTML"}]
+ * @change_log
+ * ["Since: 2.0"]
+ * @usage add_filter( 'um_user_display_name_filter', 'function_name', 10, 3 );
+ * @example
+ *
+ */
return apply_filters( 'um_user_display_name_filter', $name, um_user( 'ID' ), ( $attrs == 'html' ) ? 1 : 0 );
break;
@@ -1670,6 +2024,27 @@ function um_user( $data, $attrs = null ) {
$has_profile_photo = false;
$photo_type = 'um-avatar-default';
+
+ /**
+ * UM hook
+ *
+ * @type filter
+ * @title um_avatar_image_alternate_text
+ * @description Change user display name on um_user function profile photo
+ * @input_vars
+ * [{"var":"$display_name","type":"string","desc":"User Display Name"}]
+ * @change_log
+ * ["Since: 2.0"]
+ * @usage add_filter( 'um_avatar_image_alternate_text', 'function_name', 10, 1 );
+ * @example
+ *
+ */
$image_alt = apply_filters( "um_avatar_image_alternate_text", um_user( "display_name" ) );
if (um_profile( 'profile_photo' )) {
@@ -1682,6 +2057,27 @@ function um_user( $data, $attrs = null ) {
$avatar_uri = um_get_default_avatar_uri();
}
+ /**
+ * UM hook
+ *
+ * @type filter
+ * @title um_user_avatar_url_filter
+ * @description Change user avatar URL
+ * @input_vars
+ * [{"var":"$avatar_uri","type":"string","desc":"Avatar URL"},
+ * {"var":"$user_id","type":"int","desc":"User ID"}]
+ * @change_log
+ * ["Since: 2.0"]
+ * @usage add_filter( 'um_user_avatar_url_filter', 'function_name', 10, 2 );
+ * @example
+ *
+ */
$avatar_uri = apply_filters( 'um_user_avatar_url_filter', $avatar_uri, um_user( 'ID' ) );
@@ -1723,12 +2119,34 @@ function um_user( $data, $attrs = null ) {
$is_default = true;
}
+ /**
+ * UM hook
+ *
+ * @type filter
+ * @title um_user_cover_photo_uri__filter
+ * @description Change user avatar URL
+ * @input_vars
+ * [{"var":"$cover_uri","type":"string","desc":"Cover URL"},
+ * {"var":"$is_default","type":"bool","desc":"Default or not"},
+ * {"var":"$attrs","type":"array","desc":"Attributes"}]
+ * @change_log
+ * ["Since: 2.0"]
+ * @usage add_filter( 'um_user_cover_photo_uri__filter', 'function_name', 10, 3 );
+ * @example
+ *
+ */
$cover_uri = apply_filters( 'um_user_cover_photo_uri__filter', $cover_uri, $is_default, $attrs );
- if ($cover_uri)
+ if ( $cover_uri )
return '

';
- if (!$cover_uri)
+ if ( ! $cover_uri )
return '';
break;
diff --git a/includes/widgets/class-um-search-widget.php b/includes/widgets/class-um-search-widget.php
index 648832d3..382016ff 100644
--- a/includes/widgets/class-um-search-widget.php
+++ b/includes/widgets/class-um-search-widget.php
@@ -24,6 +24,28 @@ class UM_Search_Widget extends \WP_Widget {
// Creating widget front-end
public function widget( $args, $instance ) {
+
+ /**
+ * UM hook
+ *
+ * @type filter
+ * @title widget_title
+ * @description UM Search Widget Title
+ * @input_vars
+ * [{"var":"$title","type":"string","desc":"UM Search Widget Title"}]
+ * @change_log
+ * ["Since: 2.0"]
+ * @usage
+ *
+ * @example
+ *
+ */
$title = apply_filters( 'widget_title', $instance['title'] );
// before and after widget arguments are defined by themes
diff --git a/templates/profile.php b/templates/profile.php
index d462636e..df0a8cfa 100644
--- a/templates/profile.php
+++ b/templates/profile.php
@@ -2,36 +2,58 @@
+ if ( um_is_on_edit_profile() ) { ?>
+
-
+ do_action('um_profile_header_cover_area', $args );
+ do_action('um_profile_header', $args );
+
+ /**
+ * UM hook
+ *
+ * @type filter
+ * @title um_profile_navbar_classes
+ * @description Additional classes for profile navbar
+ * @input_vars
+ * [{"var":"$classes","type":"string","desc":"UM Posts Tab query"}]
+ * @change_log
+ * ["Since: 2.0"]
+ * @usage
+ *
+ * @example
+ *
+ */
+ $classes = apply_filters( 'um_profile_navbar_classes', '' ); ?>
+
+
+
+ profile()->active_tab;
+ $subnav = ( get_query_var('subnav') ) ? get_query_var('subnav') : 'default';
+
+ print "
";
+
+ // Custom hook to display tabbed content
+ do_action("um_profile_content_{$nav}", $args);
+ do_action("um_profile_content_{$nav}_{$subnav}", $args);
+
+ print "
";
+
+ if ( um_is_on_edit_profile() ) { ?>
+
+