Skip to content

Instantly share code, notes, and snippets.

@gaupoit
gaupoit / My_DB_Uninstall.php
Created August 1, 2018 14:42
My_DB_Uninstall.php
<?php
class My_Table {
....
public function uninstall() {
global $wpdb;
$wpdb->query("DROP TABLE IF EXISTS $this->table_name");
}
}
@gaupoit
gaupoit / My_DB_run.php
Created August 1, 2018 14:50
MyDB run
<?php
class My_Table {
protected $table_version;
protected $table_name;
...
public function run() {
$this->init();
//call the functions to update version here.
<?php
class My_Table {
protected $table_version;
protected $table_name;
public function __contruct() {
global $wpdb;
$this->db_version = get_option('my_table_version') === false ? '1.0' : get_option('my_table_version');
$this->table_name = $wpdb->prefix . 'my_table';
}
@gaupoit
gaupoit / db_init.php
Last active August 2, 2018 01:58
Activation hook to call DB init
<?php
...
register_activation_hook( __FILE__, 'activate_my_plugin' );
function activate_my_plugin() {
$db = new My_Table();
$db->run();
}
...
@gaupoit
gaupoit / s3-services.php
Created August 5, 2018 09:56
PHP class to create presigned request for uploading the file
<?php
use Aws\S3\S3Client;
if ( ! class_exists( 'S3_Service' ) ) {
/**
* Class SSU_S3_Service
*/
class S3_Service {
/**
* S3 class
@gaupoit
gaupoit / config.yml
Created August 10, 2018 07:35
Build 3rd-party library for AWS Lambda function on CircleCI?
version: 2
jobs:
build:
docker:
- image: circleci/node:8.10
working_directory: ~/lambda_func
steps:
- checkout
@gaupoit
gaupoit / fast_img.php
Last active August 12, 2018 10:16
Convert img tag into fast-img tag in the post's content or Woocommerce product's image
<?php
add_filter('the_content', 'pda_convert_img_to_fast_img', 10 );
/**
* Convert img tag to fast-img tag in the post's content
* @param $content The post's content
*
* @return mixed The massage content
*/
@gaupoit
gaupoit / create_private_link.php
Last active August 29, 2018 06:34
How to create a private link with Prevent direct accecs WordPress Plugin
@gaupoit
gaupoit / protect_wp_file.php
Last active September 28, 2018 03:24
How to protect WordPress attachment's file with Prevent Direct Access service
<?php
if ( class_exists( 'PDA_Private_Link_Services' ) ) {
//669 is attachment's id.
$result = PDA_Private_Link_Services::protect_file( 669 );
if ( is_wp_error( $result ) ) {
echo $result->get_error_message();
}
}
@gaupoit
gaupoit / hook_before_sending_file.php
Created September 27, 2018 13:33
PDA_HOOK_BEFORE_SENDING_FILE
<?php
function handle_pda_before_sending_file_hook( $server_data, $link_data ) {
//Write code to handle data here
}
add_action( 'PDA_HOOK_BEFORE_SENDING_FILE', 'handle_pda_before_sending_file_hook', 10, 2 );
?>