Skip to content

Instantly share code, notes, and snippets.

View codename065's full-sized avatar
🐢

Shahnur Alam codename065

🐢
View GitHub Profile
@codename065
codename065 / wpdm_after_upload_file.php
Last active August 12, 2021 15:09
Rename file after upload
<?php
/* Rename file */
add_action("wpdm_after_upload_file", function ($file_path) {
$dir = dirname($file_path);
$file = basename($file_path);
$ext = \WPDM\libs\FileSystem::fileExt($file);
$new_name = str_replace(".{$ext}", "-".uniqid().".{$ext}", $file);
$new_path = $dir.'/'.$new_name;
@codename065
codename065 / disable-copy.php
Created February 4, 2021 08:10
How to Disable Text Selection, Copy/Paste and Context Menu on right mouse button click in WordPress
<?php
function your_function() {
?>
<script>
jQuery(document).ready(function(){
function disableselect(e) {
return false;
};
function reEnable() {
return true;
@codename065
codename065 / allow-svg-upload.php
Created December 4, 2020 17:36
Allow SVG file type upload
<?php
add_filter("wpdm_blocked_file_types", function ($file_types){
$index = array_search('svg', $file_types);
if($index !== false) unset($file_types[$index]);
return $file_types;
});
<!DOCTYPE html>
<html>
<head>
</head>
<body>
<form>
<label>Due Date</label>
<input type="datetime-local" id="test-date">
<button id="btn" onclick='convertdate()'>Convert</button>
{
"Version": "2012-10-17",
"Statement": [
{
"Sid": "VisualEditor0",
"Effect": "Allow",
"Action": [
"s3:ListAllMyBuckets",
"s3:GetBucketLocation"
],
@codename065
codename065 / send-update-notifications.php
Created May 16, 2020 17:29
Send update notification to the users who previously downloaded the package
<?php
function wpdm_send_update_notification($ID, $post, $update){
global $wpdb;
if (get_post_type() != 'wpdmpro' || wp_is_post_revision( $ID ) || $post->post_status !== 'publish') return;
$users = $wpdb->get_results("select uid from {$wpdb->prefix}ahm_download_stats where pid = '{$ID}' and uid != 0");
$emails = [];
foreach ($users as $user){
if((int)$user->uid > 0)
$emails[] = get_user_by('ID', $user->uid)->user_email;
@codename065
codename065 / remove-from-search.php
Created April 5, 2020 05:44
Remove Download Manager Packages from search
<?php
function wpdm_remove_search($query) {
if ($query->is_search) {
$post_type = array('post', 'page');
$query->set('post_type', $post_type);
};
return $query;
};
add_filter('pre_get_posts', 'wpdm_remove_search');
@codename065
codename065 / download-count-display.php
Last active April 5, 2023 02:01
Display downloads count as 1000 as 1K, 1,000,000 1M
<?php
function wpdm__number_format($number, $plus = true){
$origin_number = $number;
if($number > 1000000){
$number = number_format(($number/1000000), 1);
$number = $origin_number > $number && $plus ? $number.'M+':$number.'M';
return $number;
}
if($number > 1000){
$number = number_format(($number/1000), 1);
@codename065
codename065 / testpay.php
Created February 2, 2020 18:04
Sample payment gateway code for promembership plugin
<?php
if (!class_exists('wpmps_testpay')) {
class wpmps_testpay {
var $TestMode;
var $GatewayUrl = "https://test.pay/purchase";
var $Account;
var $ReturnUrl;
define('AUTH_KEY', 'put your unique phrase here');
define('SECURE_AUTH_KEY', 'put your unique phrase here');
define('LOGGED_IN_KEY', 'put your unique phrase here');
define('NONCE_KEY', 'put your unique phrase here');
define('AUTH_SALT', 'put your unique phrase here');
define('SECURE_AUTH_SALT', 'put your unique phrase here');
define('LOGGED_IN_SALT', 'put your unique phrase here');
define('NONCE_SALT', 'put your unique phrase here');