Files
ultimatemember/core/um-actions-ajax.php
T

157 lines
4.4 KiB
PHP
Raw Normal View History

2014-12-15 22:38:07 +02:00
<?php
2016-02-16 16:10:31 -08:00
2014-12-15 22:38:07 +02:00
/***
2015-04-07 20:10:23 +02:00
*** @fallback for ajax urls
2014-12-15 22:38:07 +02:00
***/
add_action('wp_head','ultimatemember_ajax_urls');
add_action('admin_head','ultimatemember_ajax_urls');
function ultimatemember_ajax_urls() { ?>
2016-02-16 16:10:31 -08:00
2014-12-15 22:38:07 +02:00
<script type="text/javascript">
2016-02-16 16:10:31 -08:00
2014-12-15 22:38:07 +02:00
var ultimatemember_image_upload_url = '<?php echo um_url . 'core/lib/upload/um-image-upload.php'; ?>';
var ultimatemember_file_upload_url = '<?php echo um_url . 'core/lib/upload/um-file-upload.php'; ?>';
var ultimatemember_ajax_url = '<?php echo admin_url('admin-ajax.php'); ?>';
2016-02-16 16:10:31 -08:00
2014-12-15 22:38:07 +02:00
</script>
2016-02-16 16:10:31 -08:00
2014-12-15 22:38:07 +02:00
<?php
2015-04-07 20:10:23 +02:00
2014-12-29 15:51:55 +02:00
}
2016-02-16 16:10:31 -08:00
2015-01-22 18:36:29 +02:00
/***
*** @remove any file silently
***/
add_action('wp_ajax_nopriv_ultimatemember_remove_file', 'ultimatemember_remove_file');
add_action('wp_ajax_ultimatemember_remove_file', 'ultimatemember_remove_file');
function ultimatemember_remove_file(){
global $ultimatemember;
extract($_REQUEST);
$ultimatemember->files->delete_file( $src );
}
2016-02-16 16:10:31 -08:00
2014-12-29 15:51:55 +02:00
/***
*** @remove profile photo silently
***/
add_action('wp_ajax_nopriv_ultimatemember_delete_profile_photo', 'ultimatemember_delete_profile_photo');
add_action('wp_ajax_ultimatemember_delete_profile_photo', 'ultimatemember_delete_profile_photo');
function ultimatemember_delete_profile_photo(){
global $ultimatemember;
extract($_REQUEST);
2016-02-16 16:10:31 -08:00
2015-01-11 19:07:55 +02:00
if ( !um_current_user_can('edit', $user_id ) ) die( __('You can not edit this user') );
2014-12-29 15:51:55 +02:00
$ultimatemember->files->delete_core_user_photo( $user_id, 'profile_photo' );
}
2016-02-16 16:10:31 -08:00
2014-12-29 15:51:55 +02:00
/***
*** @remove cover photo silently
***/
add_action('wp_ajax_nopriv_ultimatemember_delete_cover_photo', 'ultimatemember_delete_cover_photo');
add_action('wp_ajax_ultimatemember_delete_cover_photo', 'ultimatemember_delete_cover_photo');
function ultimatemember_delete_cover_photo(){
global $ultimatemember;
extract($_REQUEST);
2016-02-16 16:10:31 -08:00
2015-01-11 19:07:55 +02:00
if ( !um_current_user_can('edit', $user_id ) ) die( __('You can not edit this user') );
2014-12-29 15:51:55 +02:00
$ultimatemember->files->delete_core_user_photo( $user_id, 'cover_photo' );
}
2016-02-16 16:10:31 -08:00
2014-12-29 15:51:55 +02:00
/***
*** @resampling/crop images
***/
add_action('wp_ajax_nopriv_ultimatemember_resize_image', 'ultimatemember_resize_image');
add_action('wp_ajax_ultimatemember_resize_image', 'ultimatemember_resize_image');
function ultimatemember_resize_image(){
global $ultimatemember;
$output = 0;
2016-02-16 16:10:31 -08:00
2014-12-29 15:51:55 +02:00
extract($_REQUEST);
2016-02-16 16:10:31 -08:00
2014-12-29 15:51:55 +02:00
if ( !isset($src) || !isset($coord) ) die( __('Invalid parameters') );
2016-02-16 16:10:31 -08:00
2014-12-29 15:51:55 +02:00
$coord_n = substr_count($coord, ",");
if ( $coord_n != 3 ) die( __('Invalid coordinates') );
2016-02-16 16:10:31 -08:00
2014-12-29 15:51:55 +02:00
$um_is_temp_image = um_is_temp_image( $src );
if ( !$um_is_temp_image ) die( __('Invalid Image file') );
2016-02-16 16:10:31 -08:00
2014-12-29 15:51:55 +02:00
$crop = explode(',', $coord );
$crop = array_map('intval', $crop);
2016-02-16 16:10:31 -08:00
2014-12-29 15:51:55 +02:00
$uri = $ultimatemember->files->resize_image( $um_is_temp_image, $crop );
// If you're updating a user
if ( isset( $user_id ) && $user_id > 0 ) {
$uri = $ultimatemember->files->new_user_upload( $user_id, $um_is_temp_image, $key );
}
2016-02-16 16:10:31 -08:00
2014-12-29 15:51:55 +02:00
$output = $uri;
2016-02-16 16:10:31 -08:00
2015-05-18 14:12:50 +03:00
delete_option( "um_cache_userdata_{$user_id}" );
2016-02-16 16:10:31 -08:00
2014-12-29 15:51:55 +02:00
if(is_array($output)){ print_r($output); }else{ echo $output; } die;
2015-01-24 23:39:43 +02:00
}
2016-02-16 16:10:31 -08:00
2015-01-24 23:39:43 +02:00
/***
*** @run an ajax action on the fly
***/
add_action('wp_ajax_nopriv_ultimatemember_muted_action', 'ultimatemember_muted_action');
add_action('wp_ajax_ultimatemember_muted_action', 'ultimatemember_muted_action');
function ultimatemember_muted_action(){
global $ultimatemember;
extract($_REQUEST);
2016-02-16 16:10:31 -08:00
2015-01-24 23:39:43 +02:00
if ( !um_current_user_can('edit', $user_id ) ) die( __('You can not edit this user') );
2016-02-16 16:10:31 -08:00
2015-01-24 23:39:43 +02:00
switch( $hook ) {
default:
do_action("um_run_ajax_function__{$hook}", $_REQUEST);
break;
}
2015-01-25 19:59:18 +02:00
}
2016-02-16 16:10:31 -08:00
2015-01-25 19:59:18 +02:00
/***
*** @run an ajax pagination on the fly
***/
add_action('wp_ajax_nopriv_ultimatemember_ajax_paginate', 'ultimatemember_ajax_paginate');
add_action('wp_ajax_ultimatemember_ajax_paginate', 'ultimatemember_ajax_paginate');
function ultimatemember_ajax_paginate(){
global $ultimatemember;
extract($_REQUEST);
2016-02-16 16:10:31 -08:00
2015-01-25 19:59:18 +02:00
ob_start();
2016-02-16 16:10:31 -08:00
2015-01-25 19:59:18 +02:00
do_action("um_ajax_load_posts__{$hook}", $args);
2016-02-16 16:10:31 -08:00
2015-01-25 19:59:18 +02:00
$output = ob_get_contents();
ob_end_clean();
2016-02-16 16:10:31 -08:00
2015-01-25 19:59:18 +02:00
die($output);
2016-02-16 16:10:31 -08:00
}
/***
*** @run check if username exists
***/
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 );
if( $exists ) {
echo 1;
} else {
echo 0;
}
die();
}